1、规则要求
https://www.python.org/dev/peps/pep-0008
2、工具
https://github.com/jcrocholl/pep8
3、基本使用方法
测试自己的代码:
[guosong@etch171 mars171 guosong]# pep8 --first count.py
count.py:2:1: E265 block comment should start with '# '
count.py:4:19: E231 missing whitespace after ':'
count.py:6:1: E302 expected 2 blank lines, found 1
count.py:12:5: E303 too many blank lines (2)
count.py:18:20: E225 missing whitespace around operator
count.py:31:21: W291 trailing whitespace
相同类型只显示第一条
查看详情
[root@etch171 10.55.22.171 guosong]# pep8 --show-source --show-pep8 count.py
count.py:4:19: E231 missing whitespace after ':'
item_count = {'99':0,'90':0,'80':0,'60':0,'0':0}
^
Each comma, semicolon or colon should be followed by whitespace. Okay: [a, b]
Okay: (3,)
Okay: a[1:4]
Okay: a[:4]
Okay: a[1:]
Okay: a[1:4:2]
E231: ['a','b']
E231: foo(bar,baz)
E231: [{'a':'b'}]
count.py:4:21: E231 missing whitespace after ','
--show-source参数让PEP8显示每一个错误和警告对应的代码
然后按照这个提示逐个进行修改