Possible constant assignment operators ":=" and "::=" for Python
nobody at 127.0.0.1
Wed May 3 19:35:44 CEST 2006
tsaar2003 at yahoo.com wrote:
> What I'd like to see here is that b gets a copy of A so that the
> original A won't be modified as we play with b. However, as we assign a
> constant value A to b, I wouldn't want to restrict myself from playing
> with b.
If A is a list you can take a copy-slice liek this:
>>> b = A[:]
and changes to b won't affect A. For the general case where A isn't a list,
you can use the copy module to make shallow or deep copies of A.
It's not quite as simple or as strict as declaring A constant, but it works.
Or you could look at properties, there's a thread in this group within the
last couple weeks about making constants with properties.
More information about the Python-list