pep 8 constants

Steven D'Aprano steven at
Wed Jan 14 09:13:30 CET 2009

On Tue, 13 Jan 2009 23:26:54 -0800, Brendan Miller wrote:

> I tend to use constants as a means of avoiding the proliferation of
> magic literals for maintenance reasons... Like say if your example of
> FOO would have been used in 10 places. Maybe it is more pythonic to
> simply denote such a thing as simply a normal variable? 

But it isn't a "normal variable", it's a named constant, or at least it 
would be if Python enforced constanticity. Or constantness. Or whatever.

> That doesn't
> seem to give a hint that it shouldn't be assigned a second time.

Absolutely. It's rather sad that I can do this:

import math
math.pi = 3.0

I like the ability to shoot myself in the foot, thank you very much, but 
I should at least get a warning when I'm about to do so:

math.PI = 3.0  # use God-like powers to change a constant

Changing the laws of physics, one fundamental constant at a time-ly y'rs,


More information about the Python-list mailing list