首页 » InfoTech »

pyLint初体验

2018年5月3日 / 78次阅读
Python

打开支付宝首页,搜索“529018372”,即可领取红包!可重复领。

pyCheck已经很久不更新了,还是用pyLint吧(官网:https://www.pylint.org),检查python代码是否符合PEP8的标准全靠它了。

安装:

pip install pylint

然后我用pylint检查了一下最近开始的一个个人小项目BlogChecker的代码,如下:

(blogchecker) D:\pyve02\blogchecker>
(blogchecker) D:\pyve02\blogchecker>pylint BlogChecker.py
No config file found, using default configuration
************* Module BlogChecker
C: 44, 0: Trailing whitespace (trailing-whitespace)
C: 47, 0: Trailing whitespace (trailing-whitespace)
C: 52, 0: Trailing whitespace (trailing-whitespace)
C: 66, 0: Trailing whitespace (trailing-whitespace)
C: 69, 0: Trailing whitespace (trailing-whitespace)
C: 72, 0: Trailing whitespace (trailing-whitespace)
C: 73, 0: Exactly one space required after comma
logfile = open('BlogChecker_'+dt.datetime.now().strftime('%Y-%m-%d_%H-%M-%S'
)+'.csv','w')

^ (bad-whitespace)
C: 74, 0: Trailing whitespace (trailing-whitespace)
C: 77, 0: Trailing whitespace (trailing-whitespace)
C: 80, 0: Exactly one space required after comma
for k,v in linkStatus.items():
^ (bad-whitespace)
C: 96, 0: Trailing whitespace (trailing-whitespace)
C: 99, 0: Line too long (110/100) (line-too-long)
C:102, 0: Trailing whitespace (trailing-whitespace)
C:105, 0: Trailing whitespace (trailing-whitespace)
C:106, 0: Trailing whitespace (trailing-whitespace)
C:108, 0: Trailing whitespace (trailing-whitespace)
C:110, 0: Trailing whitespace (trailing-whitespace)
C:126, 0: Trailing whitespace (trailing-whitespace)
C:133, 0: Trailing whitespace (trailing-whitespace)
C:134, 0: Trailing whitespace (trailing-whitespace)
C:137, 0: Trailing whitespace (trailing-whitespace)
C:140, 0: Trailing whitespace (trailing-whitespace)
C:142, 0: Trailing whitespace (trailing-whitespace)
C:144, 0: Exactly one space required after comma
print('[ '+str(linkNum+1)+'/'+str(len(aLink))+' ] - working on:',aLink[l
inkNum])
^ (bad-w
hitespace)
C:147, 0: Trailing whitespace (trailing-whitespace)
C:149, 0: Trailing whitespace (trailing-whitespace)
C:189, 0: Exactly one space required after comma
linkStatus[aLink[linkNum]] = [None,'Head Exception', 1]
^ (bad-whitespace)
C:199, 0: Wrong continued indentation (remove 2 spaces).
r.headers['Content-Type'],
| ^ (bad-continuation)
C:200, 0: Wrong continued indentation (remove 2 spaces).
0]
| ^ (bad-continuation)
C:201, 0: Trailing whitespace (trailing-whitespace)
C:202, 0: Trailing whitespace (trailing-whitespace)
C:203, 0: Trailing whitespace (trailing-whitespace)
C:203, 0: Wrong continued indentation before block (add 4 spaces).
r.status_code == 302 or
^ | (bad-continuation)
C:204, 0: Wrong continued indentation before block (add 4 spaces).
r.status_code == 301):
^ | (bad-continuation)
C:208, 0: Trailing whitespace (trailing-whitespace)
C:215, 0: Trailing whitespace (trailing-whitespace)
C:217, 0: Trailing whitespace (trailing-whitespace)
C:222, 0: Trailing whitespace (trailing-whitespace)
C:223, 0: Wrong continued indentation (remove 1 space).
timeout=TIME_OUT,
|^ (bad-continuation)
C:223, 0: Trailing whitespace (trailing-whitespace)
C:224, 0: Wrong continued indentation (remove 1 space).
allow_redirects=False)
|^ (bad-continuation)
C:234, 0: Trailing whitespace (trailing-whitespace)
C:239, 0: Trailing whitespace (trailing-whitespace)
C:241, 0: Trailing whitespace (trailing-whitespace)
C:244, 0: Trailing whitespace (trailing-whitespace)
C:250, 0: Trailing whitespace (trailing-whitespace)
C:251, 0: Trailing whitespace (trailing-whitespace)
C:260, 0: Trailing whitespace (trailing-whitespace)
C:265, 0: Trailing whitespace (trailing-whitespace)
C:268, 0: Trailing newlines (trailing-newlines)
W: 28, 0: Anomalous backslash in string: '\.'. String constant might be missing
an r prefix. (anomalous-backslash-in-string)
W: 28, 0: Anomalous backslash in string: '\.'. String constant might be missing
an r prefix. (anomalous-backslash-in-string)
C: 1, 0: Module name "BlogChecker" doesn't conform to snake_case naming style (
invalid-name)
C: 1, 0: Missing module docstring (missing-docstring)
W: 21,-1: String statement has no effect (pointless-string-statement)
C: 22, 0: Constant name "linkStatus" doesn't conform to UPPER_CASE naming style
(invalid-name)
C: 26, 0: Constant name "aLink" doesn't conform to UPPER_CASE naming style (inva
lid-name)
C: 43, 0: Function name "_isGoodLink" doesn't conform to snake_case naming style
(invalid-name)
R: 53, 4: The if statement can be replaced with 'return bool(test)' (simplifiabl
e-if-statement)
R: 53, 4: Unnecessary "else" after "return" (no-else-return)
C: 59, 0: Function name "_appendLink" doesn't conform to snake_case naming style
(invalid-name)
C: 67, 0: Function name "_emailReport" doesn't conform to snake_case naming styl
e (invalid-name)
C: 71, 0: Function name "_writeOutput" doesn't conform to snake_case naming styl
e (invalid-name)
C: 78, 4: Variable name "howManyLinks" doesn't conform to snake_case naming styl
e (invalid-name)
C: 79, 4: Variable name "howManyGetException" doesn't conform to snake_case nami
ng style (invalid-name)
C: 80,10: Variable name "v" doesn't conform to snake_case naming style (invalid-
name)
C: 88,12: Variable name "howManyGetException" doesn't conform to snake_case nami
ng style (invalid-name)
C: 89,12: Variable name "u" doesn't conform to snake_case naming style (invalid-
name)
C: 95, 8: Variable name "howManyLinks" doesn't conform to snake_case naming styl
e (invalid-name)
C:103, 0: Function name "_writeCSV" doesn't conform to snake_case naming style (
invalid-name)
C:107, 0: Function name "_getNewLink" doesn't conform to snake_case naming style
(invalid-name)
C:107, 0: Argument name "htmlText" doesn't conform to snake_case naming style (i
nvalid-name)
C:112, 8: Variable name "headLinks" doesn't conform to snake_case naming style (
invalid-name)
C:115, 8: Variable name "pageLinks" doesn't conform to snake_case naming style (
invalid-name)
C:118, 8: Variable name "pageLinks" doesn't conform to snake_case naming style (
invalid-name)
C:123,12: Variable name "urlList" doesn't conform to snake_case naming style (in
valid-name)
C:128, 0: Function name "_retryWait" doesn't conform to snake_case naming style
(invalid-name)
C:135, 0: Function name "allRun" doesn't conform to snake_case naming style (inv
alid-name)
C:139, 4: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
W:176,-1: String statement has no effect (pointless-string-statement)
W:180, 8: No exception type(s) specified (bare-except)
C:179,12: Variable name "r" doesn't conform to snake_case naming style (invalid-
name)
C:183,20: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
C:205,16: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
C:211,16: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
W:225,12: No exception type(s) specified (bare-except)
C:222,16: Variable name "r" doesn't conform to snake_case naming style (invalid-
name)
C:237,20: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
C:246, 8: Variable name "linkNum" doesn't conform to snake_case naming style (in
valid-name)
R:135, 0: Too many branches (19/12) (too-many-branches)
R:135, 0: Too many statements (61/50) (too-many-statements)
C:258, 0: Function name "singleRun" doesn't conform to snake_case naming style (
invalid-name)
C:258, 0: Missing function docstring (missing-docstring)
C:262, 0: Function name "HTTPStatus" doesn't conform to snake_case naming style
(invalid-name)
C:262, 0: Missing function docstring (missing-docstring)
W:262,15: Unused argument 'url' (unused-argument)
C:266, 0: Function name "getRobotsTxt" doesn't conform to snake_case naming styl
e (invalid-name)
C:266, 0: Missing function docstring (missing-docstring)
C: 7, 0: standard import "import datetime as dt" should be placed before "impor
t requests as rq" (wrong-import-order)
C: 8, 0: standard import "import time" should be placed before "import requests
as rq" (wrong-import-order)

------------------------------------------------------------------
Your code has been rated at 2.75/10 (previous run: 2.75/10, +0.00)

(blogchecker) D:\pyve02\blogchecker>

有趣的是,pyLint最后还给代码有个级别评价,我的代码值得了2.75/10.

保持项目组python代码风格统一,就靠pyLint。不需要任何其他配置,pyLint默认就是按照PEP8的标准来检查代码。

本文链接:http://www.maixj.net/ict/pylint-17822
云上小悟 麦新杰(QQ:1093023102)

相关文章

评论是美德

《pyLint初体验》有1条评论

无力满足评论实名制,评论对非实名注册用户关闭,有事QQ:1093023102.

  • 麦新杰

    专业术语:静态代码检测 [ ]


前一篇:
后一篇:

栏目精选

云上小悟,麦新杰的独立博客

栏目

支付宝红包.每天领一次.

支付宝扫码领红包

©Copyright 麦新杰 Since 2014 云上小悟独立博客版权所有 备案号:苏ICP备14045477号-1。云上小悟网站部分内容来源于网络,转载目的是为了整合信息,收藏学习,服务大家,有些转载内容也难以判断是否有侵权问题,如果侵犯了您的权益,请及时联系站长,我会立即删除。

网站二维码
go to top