[Python-Dev] Constants
Christopher Petrilli
petrilli@amber.org
Wed, 31 May 2000 14:17:57 -0400
Eric S. Raymond [esr@snark.thyrsus.com] wrote:
> I just looked at Jeremy Hylton's warts posting
> at <http://starship.python.net/crew/amk/python/writing/warts.html>
>
> It reminded me that one feature I really, really want in Python 3000
> is the ability to declare constants. Assigning to a constant should
> raise an error.
>
> Is this on the to-do list?
I know this isn't "perfect", but what I do often is have a
Constants.py file that has all my constants in a class which has
__setattr__ over ridden to raise an exception. This has two things;
1. Difficult to modify the attributes, at least accidentally
2. Keeps the name-space less poluted by thousands of constants.
Just an idea, I think do this:
constants = Constants()
x = constants.foo
Seems clean (reasonably) to me.
I think I stole this from the timbot.
Chris
--
| Christopher Petrilli
| petrilli@amber.org