Is this a refrence issue?
exarkun at divmod.com
Wed Dec 28 23:48:53 CET 2005
On Wed, 28 Dec 2005 14:40:45 -0800, "Carl J. Van Arsdall" <cvanarsdall at mvista.com> wrote:
>> I understand that everything in python is a refrence....
>> I have a small problem..
>> I have a list and want to make a copy of it and add an element to the
>> end of the new list,
>> but keep the original intact....
>> tmp = myList
>tmp = myList is a shallow copy
"tmp = myList" isn't a copy at all. A shallow copy is like this:
tmp = myList[:]
or like this:
tmp = copy.copy(myList)
This is as opposed to a deep copy, which is like this:
tmp = copy.deepcopy(myList)
What "tmp = myList" does is to create a new *reference* to the
very same list object.
More information about the Python-list