Question
Asked By – Amanda
I’m still getting used to Python conventions and using Pylint to make my code more Pythonic, but I’m puzzled by the fact that Pylint doesn’t like single character variable names. I have a few loops like this:
for x in x_values:
my_list.append(x)
and when I run pylint
, I’m getting Invalid name "x" for type variable (should match [a-z_][a-z0-9_]{2,30}
— that suggests that a valid variable name must be between 3 and 31 characters long, but I’ve looked through the PEP8 naming conventions and I don’t see anything explicit regarding single lower case letters, and I do see a lot of examples that use them.
Is there something I’m missing in PEP8 or is this a standard that is unique to Pylint?
Now we will see solution for issue: Why does Pylint object to single-character variable names?
Answer
Pylint checks not only PEP8 recommendations. It has also its own recommendations, one of which is that a variable name should be descriptive and not too short.
You can use this to avoid such short names:
my_list.extend(x_values)
Or tweak Pylint’s configuration to tell Pylint what variable name are good.
This question is answered By – warvariuc
This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0