Pylint无效的常量名称 [英] Pylint invalid constant name
问题描述
我收到有关我的常量的Pylint错误: MIN_SOIL_PARTICLE_DENS
(无效名称)。
为什么这个常数是错误的?这是我的全部功能:
I'm receiving a Pylint error regarding my constant: MIN_SOIL_PARTICLE_DENS
(invalid name).
Any ideas why this constant is wrong? Here's my full function:
def bulk_density(clay, sand, organic_matter):
MIN_SOIL_PARTICLE_DENS = 2.65
x1 = (0.078 + 0.278 * sand + 0.034 * clay + 0.022 * organic_matter - 0.018
* sand * organic_matter - 0.027 * clay * organic_matter - 0.584 * sand
* clay)
x2 = -0.107 + 1.636 * x1
field_capacity = vol_water_content_33_j_kg(clay, sand, organic_matter)#m3/m3
sat_water_content = 0.043 + field_capacity + x2 - 0.097 * sand
return (1 - sat_water_content) * MIN_SOIL_PARTICLE_DENS
推荐答案
检查名称时,Pylint区分常量,变量,类等。不在函数/类内的任何名称都将被视为常量,其他任何东西都将是变量。
When checking names, Pylint differentiates between constants, variables, classes etc. Any name that is not inside a function/class will be considered a constant, anything else is a variable.
请参见 http://docs.pylint.org/features.html#basic-checker
变量rgx:
[a-z _] [a-z0-9 _] {2,30} $
const-rgx:
(([[A-Z _] [A-Z0 -9 _] *)|(__。* __))$
const-rgx:
(([A-Z_][A-Z0-9_]*)|(__.*__))$
因为您在函数, MIN_SOIL_PARTICLE_DENS
应该是变量(根据pylint),但是pylint将其视为常量,因此会抱怨。
Because you're in a function, MIN_SOIL_PARTICLE_DENS
is (according to pylint) supposed to be a variable, pylint however treats it as a constant and therefore complains.
这意味着您不能在函数中使用任何大写名称,而不会受到pylint的抱怨。
This means you can't have any uppercase names inside functions without pylint complaining.
如果您问我,使用大写内部函数就可以了;并非所有常量都必须全局定义。
If you ask me, using uppercase inside functions is fine; not all constants are necessarily defined globally.
这篇关于Pylint无效的常量名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!