首页 > 代码库 > PEP8
PEP8
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 1count.py:12:5: E303 too many blank lines (2)count.py:18:20: E225 missing whitespace around operatorcount.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显示每一个错误和警告对应的代码
然后按照这个提示逐个进行修改
PEP8
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。