const in Python

Gordon McMillan gmcm at hypernet.com
Mon Feb 7 11:58:26 EST 2000


Anders M Eriksson writes:
> 
> Would someone please explain why there isn't a const 'operator' in
> Python!

For the same reason that there's no private, protected stuff. 
Python is based on the trust model, which keeps the 
language simple. And it works pretty well, since programmers 
are generally well behaved, except, of course, in the presence 
of cheese.
 
> Very often I have constants in my code and it would be nice if Python
> could check that someone (.I.) don't change them!

If you are truly concerned, you could make them attributes of 
a class that prohibits setattr. But generally naming 
"constants" in all upper case is enough to tell a Pythonista 
that it shouldn't be modified.

- Gordon




More information about the Python-list mailing list