python的类名一定要大写吗_为什么pylint在函数之外需要大写的变量名?

为什么pylint在函数外部接受大写变量,而在函数内部拒绝它们?相反,为什么pylint在函数外拒绝camelCase而在函数内接受它?在

我刚刚安装了pylint(2.2.2版)来检查我的python3。我一定错过了什么。我的相关Python/package版本是:pylint 2.2.2

astroid 2.1.0

Python 3.6.7 | packaged by conda-forge | (default, Nov 20 2018, 18:20:05)

[GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.37)]

考虑下面的代码(test_1),其中我使用camelCase并以大写形式命名变量。大写变量被接受(为什么?)camelCase被拒绝了(我猜是因为代码没有被包装成函数)。在

^{pr2}$

打电话给派林特:$ pylint --py3k --enable=all test_1.py

************* Module test_1

test_1.py:5:0: C0103: Constant name "fileHandler" doesn't conform to UPPER_CASE naming style (invalid-name)

------------------------------------------------------------------

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

现在如果我把所有的东西都放到一个函数中(测试2)。在'''

Nothing important

'''

def foo():

fileHandler = open("afile.txt")

for line in fileHandler:

Token = line.split("\t")

Part_1 = Token[0]

print(Part_1)

if __name__ == '__main__':

foo()

然后大写的变量被检测为不兼容(这是我所期望的):$ pylint --py3k --enable=all test_2.py

************* Module test_2

test_2.py:5:0: C0102: Black listed name "foo" (blacklisted-name)

test_2.py:5:0: C0111: Missing function docstring (missing-docstring)

test_2.py:6:4: C0103: Variable name "fileHandler" doesn't conform to snake_case naming style (invalid-name)

test_2.py:9:8: C0103: Variable name "Token" doesn't conform to snake_case naming style (invalid-name)

test_2.py:10:8: C0103: Variable name "Part_1" doesn't conform to snake_case naming style (invalid-name)

------------------------------------------------------------------

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

我有些不清楚的事情。。。欢迎澄清。。。在

最佳

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值