Copy an Object (Again?)
Alex Martelli
aleax at mail.comcast.net
Sat Jan 7 13:41:52 EST 2006
KraftDiner <bobrien18 at yahoo.com> wrote:
...
> objs = myListOfObjects
> for obj in objs:
> if obj.flag:
> newObject = copy.deepcopy(obj)
> newObject.mirror()
> myListOfObjects.append(newObject)
Never modify the very list you're looping on. I doubt this is the root
of your problem, but, at any rate, loop on a COPY of the list you're
modifying -- e.g. change the first statement to
objs = list(myListOfObjects)
Alex
More information about the Python-list
mailing list