Good modernization advice from Terry J. Reedy:

Don't use list, dict, file, and such as variable names.
This commit is contained in:
Raymond Hettinger 2003-01-15 01:55:12 +00:00
parent 87e4c7b2c1
commit f6e3df20d0
1 changed files with 15 additions and 0 deletions

View File

@ -180,6 +180,21 @@ sufficient for most uses.
Locating: ``grep types *.py | grep import``
Avoid Variable Names that Clash with the ``__builtins__`` Module
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
In Python 2.2, new built-in types were added for ``dict`` and ``file``.
Scripts should avoid assigning variable names that mask those types.
The same advice also applies to existing builtins like ``list``.
Pattern::
file = open('myfile.txt') --> f = open('myfile.txt')
dict = obj.__dict__ --> d = obj.__dict__
Locating: ``grep 'file ' *.py``
Python 2.1 or Later
-------------------