Pylint 在输出中显示无效的变量名称 [英] Pylint showing invalid variable name in output
本文介绍了Pylint 在输出中显示无效的变量名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我制作了一个简单的 Python 脚本来在网站上发布数据.
I made a simple python script to post data on a website.
#Imports
url_to_short = sys.argv[1]
post_url = 'https://www.googleapis.com/urlshortener/v1/url'
headers = {'Content-Type': 'application/json'}
data = {'longUrl': url_to_short}
post_data = json.dumps(data)
req = urllib2.Request(post_url, post_data, headers)
resp = urllib2.urlopen(req)
if resp.getcode() == 200:
content = json.loads(resp.read())
#Other stuff
现在我想让我们用 pylint
工具检查我的脚本的编码标准.
Now I thought lets check my script for coding standards with pylint
tool.
我的pylint
输出如下:
************* Module post
C: 1,0: Missing docstring
C: 6,0: Invalid name "url_to_short" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 8,0: Invalid name "post_url" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
C: 9,0: Invalid name "headers" (should match (([A-Z_][A-Z0-9_]*)|(__.*__))$)
# Other stuff
现在,我的问题是为什么 pylint
将我的变量名称显示为 Invalid name
.以这种方式命名变量是否是错误的编码约定.
Now, my question is why pylint
is showing my variable names as Invalid name
. Is naming variable this way a wrong coding convention.
我的完整的pylint输出.
推荐答案
由于您的代码未包含在类或函数中,因此期望这些变量为 常量,因此它们应该是大写的.
As your code is not contained in a class or function it is expecting those variables to be constants and as such they should be uppercase.
您可以阅读PEP8了解更多信息.
You can read PEP8 for further information.
这篇关于Pylint 在输出中显示无效的变量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文