On Mon, 19 Aug 2013 09:32:53 +0100, Chris Angelico wrote: > Python does have constants. It just doesn't have interpreter support for > them. Same as private members, in fact.
"Constant by convention". I wish Python had stronger support for enforcing constantness, to whit, some way to say "you can't rebind or delete this name once it is bound". You can do it with attributes, by use of property, or in C extensions, but you cannot do it with top-level name bindings. It makes me terribly sad that you can do this: import math math.pi = 3.0 although I can't decide whether I am less sad or more sad to see that the behaviour of math.sin and friends doesn't depend on math.pi. Now, of course, and I don't expect any such "constants" to be proof against a dedicated attacker. One can work around read-only properties, and I expect that any future "no-rebind" constants will also be capable of being worked around. This is Python, not Haskell or Ada. But, naming convention or no naming convention, it is still valuable to get an exception if you accidentally rebind something that you shouldn't rebind. -- Steven -- http://mail.python.org/mailman/listinfo/python-list