[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Sticky Variables



Kris Schnee 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?
>
In the case of lists you can use the more compact (though arguably less
clear) "a = code['.'][:]".

--Noah


Attachment: signature.asc
Description: OpenPGP digital signature