PEP8: conflict between W292 and W391

余生长醉 提交于 2019-12-05 08:35:32

问题


As far as I know in unix it's a good practice to always have blank line at the end of file - or to put it in other words: every line should end with \n.

While checking my python code with PEP8 I noticed that it also states that there should be \n at end of file:

W292 no newline at end of file
    JCR: The last line should have a newline.

What's strange, it conflicts with W391:

W391 blank line at end of file
    JCR: Trailing blank lines are superfluous.

    Okay: spam(1)
    W391: spam(1)\n

How it should be? Should I have blank line at the end of file or not?


回答1:


W391 is a blank line, that is, two consecutive \ns. There is no conflict.




回答2:


This is what W391 is talking about:

print 'last line'


This is wrong according to W292:

print 'last line'

What is correct is:

print 'last line'




回答3:


In Windows '\n' is the separator between lines, but in Linux '\n' is the ending sign on any line. Vim did nothing wrong to add '\n' to the end of lines in Linux platform but following OS definition.



来源:https://stackoverflow.com/questions/9768139/pep8-conflict-between-w292-and-w391

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!