Possible constant assignment operators ":=" and "::=" for Python
Fredrik Lundh
fredrik at pythonware.com
Wed May 3 02:23:05 EDT 2006
tsaar2003 at yahoo.com wrote:
> For example:
>
> >>> A = [] # let's declare a "constant" here
> >>> b = A # and let's assign the constant here
> >>> b.append('1') # OOPS!
> >>> c = A
> >>> print A
> ['1']
> >>> print b
> ['1']
> >>> print c
> ['1']
>
> As you can see, the "constant" A can be modified this easily. But if
> there were an intuitive mechanism to declare a symbol to be immutable,
> then there won't be this problem.
why are you using mutable objects as constants?
(insert obligatory "it hurts when I do this" joke here)
btw, given a hypothetical "object that symbol points to is immutable" syntax,
what would you expect this to do ?
>>> constant A = []
>>> b = [A]
>>> # much later
>>> b[0].append('1')
</F>
More information about the Python-list
mailing list