deepcopy alternative?

none "trades\" at (none)
Mon Jan 29 18:17:11 EST 2007


I have a very complex data structure which is basically a class object 
containing (sometimes many) other class objects, function references, 
ints, floats, etc.  The man for the copy module states pretty clearly 
that it will not copy methods or functions.  I've looked around for a 
while (prob just using the wrong keywords) and haven't found a good 
solution.  As a workaround I've been using cPickle, loads(dumps(obj)) 
which is incredibly slow (~8 sec for a 1000 elem list).

I believe the only thing stopping me from doing a deepcopy is the 
function references, but I'm not sure.  If so is there any way to 
transform a string into a function reference(w/o eval or exec)?

Example
from copy import deepcopy
a = ClassObj([ClassObj([3.2, 'str', funcRef]), 4, ClassObj[funcRef])
b = deepcopy(a)
TypeError: function() takes at least 2 arguments (0 given)

All I want is a deepcopy of the list.  Any suggestions would be appreciated.

Jack Trades

PS: If the answer to this is in __getstate__() or __setstate__() is 
there some reference to how these should be implemented besides the 
library reference?



More information about the Python-list mailing list