[Tutor] copying

Suzanne Little s349929@student.uq.edu.au
Mon, 21 Aug 2000 15:12:16 +1000 (GMT+1000)


Hello, 

I've run across a bit of a problem and I'm hoping that either it's
all my fault because I've done something silly  or someone can suggest a
solution. Over the weekend I was very excited to find the generic shallow
and deep copying operations because they were exactly what I needed at
that point in my coding. I got the functions working on some basic
examples but when I sat down to try it out on the real thing I've found
that since I'm using kjSets as one of the data types in my list deepcopy
doesn't work. Sample code from an investigation session is below.

My question: Is there anyway of getting around this? I really need
deepcopy to work regardless of what you give it since I'm getting it to
copy the __dict__ of an object. Am I likely to run into this problem again
with other objects? 

Alternatively is there another way that I can take a 'snapshot' of the
__dict__ and put it into a stack?

Thanks for any and all help,
Suzanne

Python 1.5.2 (#1, Nov 25 1999, 16:33:11)  [GCC 2.95.2 19991024 (release)]
on sunos5
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> from kjbuckets import *   
>>> from copy import *
>>> s = kjSet(1,2,3)
>>> c = copy(s)
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/opt/local/PACKAGES/Python-1.5.2/lib/python1.5/copy.py", line 72,
in copy
    raise error, \
copy.error: un(shallow)copyable object of type <type 'kjSet'>
>>> g = kjGraph((1,2),(2,3))
>>> c2 = copy(g)   
Traceback (innermost last):
  File "<stdin>", line 1, in ?
  File "/opt/local/PACKAGES/Python-1.5.2/lib/python1.5/copy.py", line 72,
in copy
    raise error, \
copy.error: un(shallow)copyable object of type <type 'kjGraph'>


--------------------------------------------------------------------------
"Contrariwise," continued Tweedledee, "If it was so, it might be; and if
it were so, it would be; but as it isn't, it ain't.  That's logic"
                             -Lewis Carroll
--------------------------------------------------------------------------