[Python-Dev] PEP 8 updates/clarifications

François Pinard pinard at iro.umontreal.ca
Thu Dec 15 03:21:39 CET 2005


[Barry Warsaw]

>I've pushed out a revised PEP 8
>http://www.python.org/peps/pep-0008.html
>Please review and comment.

Hi, Barry, and people.  Allow me a few remarks, nothing essential.


* Within "Naming Conventions", "Prescriptive: Naming Conventions", 
"Module names", we read:

    Modules should have short, lowercase names, without underscores.

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.


* Within "Code lay-out", "Blank Lines", we read:

    Separate top-level function and class definitions with two blank lines.

In a running English text (like in this message!), it might make sense, 
but after tried for a long while both a single line and two lines 
between top-level elements in Python programs, I did not see that two 
lines gives so much more legibility to be worth a prescription.  One 
white line is enough in my opinion, and I wonder if "with two blank 
lines" could not be replaced by "at least one blank line".


* Within "Programming Recommendations", writers are suggested to prefer 
str methods of the string module, as well as a few others more recent 
additions (recent in the history of Python).  I wonder if this would not 
be a good place to suggest more of such.  These come to mind:

    - 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:".

and there might be others.  Deprecated functions could be listed, too.

-- 
François Pinard   http://pinard.progiciels-bpi.ca


More information about the Python-Dev mailing list