+ 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?

22nd Jan 2019, 12:56 PM
Pedro Tortello
Pedro Tortello - avatar
5 Antworten
+ 3
Anna thank you! The round brackets did the job. HonFu These loops have many lines inside. This particular one is the only one long enough to worry about. Besides... I will not change my code because of the beauty hahaha
22nd Jan 2019, 2:45 PM
Pedro Tortello
Pedro Tortello - avatar
+ 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.
22nd Jan 2019, 1:10 PM
Anna
Anna - avatar
+ 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?
22nd Jan 2019, 1:18 PM
HonFu
HonFu - avatar
+ 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.
22nd Jan 2019, 2:50 PM
HonFu
HonFu - avatar
+ 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.
22nd Jan 2019, 3:03 PM
Pedro Tortello
Pedro Tortello - avatar