If I understood correctly, it’s better not to use an expression for a local variable that’s already a global function in Python. So I believe this
list = [1,2,3]
is disrecommended in favor of
mylist = [1,2,3]
because list is already a built-in object in Python and mylist is not. However, I’m not always sure whether I should or should not use some expression (e.g. dir, num or cnt). Is there any comprehensive overview of the strings I’d better avoid for naming local variables?
The names to avoid are keywords (which will give you an error, so are easy to spot) and builtins, which will get silently masked. Here’s a snippet of code to test for bad names:
… and here’s a list (for Python 3.3):
Builtin functions, types etc.
Anything in CamelCase (like the builtin exceptions) or beginning with a double underscore is excluded from the list above, as you shouldn’t be using those anyway.
Keywords