Why does pylint object to single character variable names?

Amanda picture Amanda · Feb 17, 2014 · Viewed 42.1k times · Source

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?

Answer

mlncn picture mlncn · Feb 3, 2016

A little more detail on what gurney alex noted: you can tell PyLint to make exceptions for variable names which (you pinky swear) are perfectly clear even though less than three characters. Find in or add to your pylintrc file, under the [FORMAT] header:

# Good variable names which should always be accepted, separated by a comma
good-names=i,j,k,ex,Run,_,pk,x,y

Here pk (for primary key), x, and y are variable names i've added.