pep 8 constants

Ben Finney bignose+hates-spam at benfinney.id.au
Mon Jan 19 23:58:30 EST 2009


Steven D'Aprano <steven at REMOVE.THIS.cybersource.com.au> writes:

> But regardless... yes, it is in my opinion Pythonic to use ALLCAPS
> to designate constants (by convention).

I agree, in general. Though I think I can count the number of times
I've wanted to use an ‘UPPER_CASE’-named constant in my code, on the
fingers of one foot.

> It isn't in PEP 8, but I don't think that matters unless PEP 8
> suggests a different convention.

It does recommend a contradictory convention:

    Global Variable Names

      (Let's hope that these variables are meant for use inside one module
      only.)  The conventions are about the same as those for functions.

The conventions for functions are the familiar ‘lower_case’
conventions. This directly contradicts using ‘UPPER_CASE’ names.
Unless someone's going to argue that “Variable Names” doesn't apply to
constant names, even though Python doesn't make the distinction.

That said, I think upper-case name is a useful convention to
distinguish “this name binding is never expected to change” from the
common case, and wouldn't argue against its use. Perhaps I'd even
argue for an update to PEP 8 that endorses this as conventional.

-- 
 \     “I was born by Caesarian section. But not so you'd notice. It's |
  `\     just that when I leave a house, I go out through the window.” |
_o__)                                                   —Steven Wright |
Ben Finney



More information about the Python-list mailing list