[Python-Dev] PEP 8 updates/clarifications
François Pinard
pinard at iro.umontreal.ca
Thu Dec 15 04:09:45 CET 2005
[Guido van Rossum]
>On 12/14/05, François Pinard <pinard at iro.umontreal.ca> wrote:
>> I would like that PEP 0008 add some cement around this idea that common
>> English words, properly spelled, which are likely to be user variable
>> names, be avoided whenever reasonable.
>I don't think that's a reasonable rule. There are too many English
>words and the rule as formulated is too vague. Also, module/package
>names can only conflict with *global* user variable names.
It would be hard making a precise formulation for it indeed. Yet, the
danger exists and would be more easily avoided if stated in PEP 0008.
A good exemple is the "textwrap" module, for which the name is very
acceptable to me, while "text" (which was suggested here on python-dev)
would have been a bit nightmarish in my own code: I used to do a lot of
text processing, and I selected "text" as the common name for strings
under consideration, exactly because "string" was already taken! ½ :-)
I do not understand your statement that module/package names can only
conflict with *global* user variable names. Local variables hide global
variables with same names, and imported modules are often global
variables. So, using a local name in a function prevents accessing
a module by the same name (defined either locally or globally).
>> - Replacing "apply(func, args)" with "func(*args)".
>> - Replacing "for line in file.readlines():" with "for line in file:".
>> - Replacing "for key in dict.keys():" with "for key in dict:".
>> - Replacing "if has_key(dict, key):" with "if key in dict:".
>> Deprecated functions could be listed, too.
>I think that's more proper for a separate PEP -- the style guide
>shouldn't have to be updated each time something else is deprecated.
I was more thinking of things like xreadlines, having replacements
suggested in the style guile already (given you accept the second
"Replacing" above). Not every single deprecated function, of course,
but only the prominent ones. On the other hand, xreadlines is not even
prominent. :-)
--
François Pinard http://pinard.progiciels-bpi.ca
More information about the Python-Dev
mailing list