pep 8 constants

Benjamin Kaplan benjamin.kaplan at case.edu
Wed Jan 14 08:54:30 EST 2009


On Wed, Jan 14, 2009 at 3:13 AM, Steven D'Aprano <
steven at remove.this.cybersource.com.au> wrote:

> 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


(OT)

You don't need God-like powers to do that. God already did it (it's in the
bible somewhere, I don't remember where)
And the Indiana state legislature thinks that doing that changing the value
of pi is a perfectly legitimate action. (I guess they arrest all circles
whose circumfrence:diameter ratio doesn't conform to the new value ???)
http://en.wikipedia.org/wiki/Indiana_Pi_Bill

>
>
>
>
>
> Changing the laws of physics, one fundamental constant at a time-ly y'rs,
>
> --
> Steven
>  --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090114/ca720ece/attachment-0001.html>


More information about the Python-list mailing list