REPOST: [Q] Deepcopy with Python 2.2 ?
Oliver Hofmann
setar at gmx.de
Fri Dec 28 11:47:05 EST 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!
Thanks,
Oliver
---8<-----
import copy
class Base(object):
def __init__(self):
self.parent = None
object.__init__(self)
class Hit(Base):
def __init__(self):
self.hsps = []
Base.__init__(self)
class HSP(Base):
def __init__(self):
self.data = [1, 2, 3]
Base.__init__(self)
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__':
main()
========= WAS CANCELLED BY =======:
Path: news.sol.net!spool1-milwwi.newsops.execpc.com!newsfeeds.sol.net!newspump.sol.net!nntp1.roc.gblx.net!nntp.gblx.net!nntp1.phx1.gblx.net!nntp.gblx.net!nntp.gblx.net!enews.sgi.com!news-xfer.nuri.net!feeder.kornet.net!news1.kornet.net!ua4canc3ll3r
From: setar at gmx.de (Oliver Hofmann)
Newsgroups: comp.lang.python
Subject: cmsg cancel <440c5c6a.0112280847.55c92de7 at posting.google.com>
Control: cancel <440c5c6a.0112280847.55c92de7 at posting.google.com>
Date: Mon, 31 Dec 2001 03:17:44 GMT
Organization: A poorly-installed InterNetNews site
Lines: 2
Message-ID: <cancel.440c5c6a.0112280847.55c92de7 at posting.google.com>
NNTP-Posting-Host: 211.57.49.2
X-Trace: news2.kornet.net 1009775234 27193 211.57.49.2 (31 Dec 2001 05:07:14 GMT)
X-Complaints-To: usenet at news2.kornet.net
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