码迷,mamicode.com
首页 > 其他好文 > 详细

PEP8

时间:2014-11-23 17:23:17      阅读:161      评论:0      收藏:0      [点我收藏+]

标签:blog   http   ar   os   使用   sp   on   div   art   

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显示每一个错误和警告对应的代码

然后按照这个提示逐个进行修改 

PEP8

标签:blog   http   ar   os   使用   sp   on   div   art   

原文地址:http://www.cnblogs.com/gsblog/p/4116763.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!