On 5/27/07, Kris Schnee <kschnee@xxxxxxxxxx> wrote:
I've run into that "sticky variables" problem again:
>>> code = {".":[],"c":["crate"]}
>>> a = code["."]
>>> b = code["."]
>>> a ==b
True
>>> a is b
True
One solution is:
>>> import copy
>>> a = copy.copy(code["."])
>>> b = copy.copy(code["."])
>>> a == b
True
>>> a is b
False
But is there a better way to make it clear I want the value, not an
actual reference?
There are no values in Python, just references. Either you want an existing reference, or a new one. If you want a new one, then copying is usually appropriate. -bob