[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()
More information about the Python-list
mailing list