Possible constant assignment operators ":=" and "::=" for Python
Michele Simionato
michele.simionato at gmail.com
Thu May 4 05:09:29 EDT 2006
Edward Elliott wrote:
> Michele Simionato wrote:
> > Python solution is to rely on the intelligence of programmers. If they
> > see an all caps name and then they try to change it without knowing what
> > they are doing, then they are stupid. If you have stupid programmers there
> > is no way the language can stop them for making disasters.
>
> Which doesn't apply here, one of the OP's examples further up this thread
> doesn't modify any ALL CAPS vars directly:
>
> >>> A = [] # let's declare a "constant" here
> >>> b = A # and let's assign the constant here
> >>> b.append('1') # OOPS!
But it makes no sense to use a mutable object for a constant!
The user should use a tuple, or a custom list-like type where
all methods with side effects are removed, so it effectively acts
as a tuple.
Michele Simionato
More information about the Python-list
mailing list