REPOST: [Q] Deepcopy with Python 2.2 ?

Oliver Hofmann setar at
Fri Dec 28 17:47:05 CET 2001

'lo everyone!

I've had a few problems with copying objects lately when they 
reference each other. My understanding is that deepcopy should 
take care of that due to the memo - dictionary; this does not 
seem to be the case. 

The following code works fine if Base does _not_ inherit 
from object. If it does the result is:

RuntimeError: maximum recursion depth exceeded

Any help would be appreciated!



import copy

class Base(object):
    def __init__(self):
        self.parent = None

class Hit(Base):
    def __init__(self):
        self.hsps = []
class HSP(Base):
    def __init__(self): = [1, 2, 3]

def main():
    a = Hit()
    b = HSP()
    c = HSP()
    d = HSP()
    a.hsps.extend([b, c, d])
    b.parent = a
    c.parent = a
    d.parent = a

    z = copy.deepcopy(a)

if __name__ == '__main__':

========= WAS CANCELLED BY =======:
From: setar at (Oliver Hofmann)
Newsgroups: comp.lang.python
Subject: cmsg cancel <440c5c6a.0112280847.55c92de7 at>
Control: cancel <440c5c6a.0112280847.55c92de7 at>
Date: Mon, 31 Dec 2001 03:17:44 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.440c5c6a.0112280847.55c92de7 at>
X-Trace: 1009775234 27193 (31 Dec 2001 05:07:14 GMT)
X-Complaints-To: usenet at
NNTP-Posting-Date: Mon, 31 Dec 2001 05:07:14 +0000 (UTC)
X-No-Archive: yes
X-Unac4ncel: yes
X-Commentary: I love NewsAgent 1.10 and the Sandblaster Cancel Engine Build 74 (19 March 1999)

This message was cancelled from within Mozilla.

More information about the Python-list mailing list