+ 1
How to keep my code in PEP 8 style?
I have a line in my code that is inside many loops and "if" conditions: score_str = f"Score: {scorecor[0]}\t\t\tRecord: {scorecor[1]}" The last character is at column 83 in my code. I want to keep my code within the 79 characters limit as proposed by PEP 8 style. How to break it in more than 1 line?
5 Respuestas
+ 2
score_str = (f"Score: {scorecor[0]}\t\t\tRecord: "
f"{scorecor[1]}")
Doesn't look too pretty, but it will give you the same result. You can also omit the round brackets and end the first line with a backslash.
+ 2
'I have a line in my code that is inside many loops and "if" conditions.'
That sounds like your code could use some simplification.
How about transferring the job of some of the loops to a function?
+ 1
Would you like to show us the part with all the loops? Maybe someone has a good idea how you could make it simpler.
The problem is that complex code gets harder to read if you don't look at it for a while. I have seen some of my earlier codes and thought: Wait, I did that? How does it even work?
Those codes of mine I can still read after having 'forgotten' them, are usually those where I kept things simple, gave fitting names and put it all into tidy function boxes for one job each.
+ 1
I can't show it here, the main loop has more than 300 lines.
Inside the main loop I have a level loop (it is a game) and inside this I have one to check for score points. Here is where the line above is written.