Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
I am an amateur programmer writing some python for a research project at my university. I need my code to be very readable for anyone who may be working on this project after me, and as such I am trying to follow PEP 8. I have run into a conflict of rules however. The offending lines are a dictionary definition after a long string of for loops and if statements. The problem is that convention has it that no line should be longer than 79 characters, yet line continuations should be indented from where they started from. I see three options of what could logically be done, but am unsure of what is best.
option 1: leave offending lines too long
defgetIndexedData(directory):|...|...|...|# construct dictionary of images with peak locations |peaks[image]={|'Xpixel':[float(x)forxinstep[17][10][0].text.s|plit(' ')],'Ypixel':[float(x)forxinstep[17][10][1].text.s|plit(' ')]}returnpeaks|
option 2: unindent continued lines
defgetIndexedData(directory):|...|...|...|# construct dictionary of images with peak locations |peaks[image]={|'Xpixel':[float(x)forxinstep[17][10][0].text.split(' ')],|'Ypixel':[float(x)forxinstep[17][10][1].text.split(' ')]}|returnpeaks|
option 3: split definitions somewhere (not sure where)
defgetIndexedData(directory):|...|...|...|# construct dictionary of images with peak locations |peaks[image]={|'Xpixel':|[float(x)forxinstep[17][10][0].text.split(' ')],|'Ypixel':|[float(x)forxinstep[17][10][1].text.split(' ')]}|returnpeaks|
I am also open to any other suggestions :)
Thanks,
~Aaron
解决方案
A couple of relevent snippets from PEP 8 with my italics added.
A style guide is about consistency. Consistency with this style guide
is important. Consistency within a project is more important.
Consistency within one module or function is most important.
But most importantly: know when to be inconsistent -- sometimes the
style guide just doesn't apply. When in doubt, use your best judgment.
Look at other examples and decide what looks best. And don't hesitate
to ask!
... it is okay to increase the nominal line length from 80 to 100
characters (effectively increasing the maximum length to 99
characters), provided that comments and docstrings are still wrapped
at 72 characters.