PEP8 tells me that the maximum line length should be 79. This sounds a bit like punched cards, and I'm used to longer lines, but as I learn Python, I'm trying to conform to the standard style.
Consider this line:
partsList[r][newPurchaseNotes] += partsList[r+1][newPurchaseNotes]
When indented 4 stops (using 4-space tabs per PEP8), it overflows. (If I use PEP8 underscore separators rather than Java-style mixed case, it's worse.)
If I break it into two lines like this:
partsList[r][newPurchaseNotes]
+= partsList[r+1][newPurchaseNotes]
...it is a syntax error (unexpected indent). Breaking it like this:
partsList[r][newPurchaseNotes] +=
partsList[r+1][newPurchaseNotes]
...it is ALSO a syntax error (invalid syntax).
Here are two obvious solutions, neither of which I like:
- use shorter names for variables
break the one statement into two with intermediate variables:
s = partsList[r+1][newPurchaseNotes] partsList[r][newPurchaseNotes] += s
In researching this forum, I did find suggestions for reducing indentation levels for loops and for conditionals. In my case, I had if nested in if nested in a while inside a function. I changed the logic to reduce one level of if statements, but it was not enough to keep the line in 79 characters.