天天看點

pep8 python 編碼方式_Python PEP8 代碼規範常見問題及解決方法

PEP 8: no newline at end of file

解決方法:代碼末尾需要另起一行,光标移到最後回車即可

PEP 8: indentation is not a multiple of four

解決方法:縮進不是4的倍數,檢查縮進

PEP 8: over-indented

解決方法:過度縮進,檢查縮進

PEP 8: missing whitespace after’,’

解決方法:逗号後面少了空格,添加空格即可,類似還有分号或者冒号後面少了空格

PEP 8: multiple imports on one line

解決方法:不要在一句 import 中引用多個庫,舉例:import socket, urllib.error最好寫成:import socket import urllib.error

PEP 8: blank line at end of line

解決方法:代碼末尾行多了空格,删除空格即可

PEP 8: at least two spaces before inline comment

解決方法:代碼與注釋之間至少要有兩個空格

PEP 8: block comment should start with ‘#’

解決方法:注釋要以#加一個空格開始

PEP 8: inline comment should start with ‘#’

解決方法:注釋要以#加一個空格開始

PEP 8: module level import not at top of file

解決方法:import不在檔案的最上面,可能之前還有其它代碼

PEP 8: expected 2 blank lines,found 0

解決方法:需要兩條空白行,添加兩個空白行即可

PEP 8: function name should be lowercase

解決方法:函數名改成小寫即可

PEP 8: missing whitespace around operator

解決方法:操作符(’=’、’>’、’

PEP 8: unexpected spaces around keyword / parameter equals

解決方法:關鍵字/參數等号周圍出現意外空格,去掉空格即可

PEP 8: multiple statements on one line (colon)

解決方法:多行語句寫到一行了,比如:if x == 2: print('OK')要分成兩行寫

PEP 8: line too long (82 > 79 characters)

解決方法:超過了每行的最大長度限制79