PEP8: conflict between W292 and W391

2019-04-03 03:43发布

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?

标签: python pep8
3条回答
时光不老,我们不散
2楼-- · 2019-04-03 04:08

In Windows '\n' is the separator between lines, but in linux '\n' is the ending sign on any line. Vim do not thing wrong to add '\n' to the end of lines in linux platform but following os definition.

查看更多
Lonely孤独者°
3楼-- · 2019-04-03 04:18

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'

查看更多
唯我独甜
4楼-- · 2019-04-03 04:23

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

查看更多
登录 后发表回答