Milos Prudek wrote:
Milos Prudek wrote:
I think I'm going slightly mad :-)
OK, I tracked it down to what amounts to IMHO a Python feature :-O
x=['a','b','c'] x ['a', 'b', 'c'] y=x y ['a', 'b', 'c'] y.remove('b') y ['a', 'c'] x ['a', 'c']
This problem applies to lists only... a simple assignment seems to assign a reference to original variable instead of creating a copy of original variable data.
I use Python 2.1.1 on Linux.
Is this normal Python behaviour?
this is essential python behaviour. python is a language with "pointer semantics", meaning a name is just a pointer to an object (containig value & class/type) infos. see the difference between mutable/immutable objects. in pointer semantic languages, object comparison differentiates between equal value or equal value and structure. Assignment just lets your left hand ident refer to the rhs object. read beazly's essential reference. AND: from copy import copy, deepcopy. -- ------------------------------------------------------------- Who's got only a hammer sees the world as a nail hans augustin (software developer) hans@beehive.de beehive elektronische medien GmbH http://www.beehive.de phone: +49 30 847-82 0 fax: +49 30 847-82 299