How to deepcopy a list of user defined lists?

srinivasan srinivas sri_annauni at yahoo.co.in
Thu Jan 8 03:53:42 EST 2009


--> 964         self.__tmp_data = copy.deepcopy(self.__data)
    965
/usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil)
    160     copier = _deepcopy_dispatch.get(cls)
    161     if copier:
--> 162         y = copier(x, memo)
    163     else:
    164         try:
/usr/local/python-2.5.1/lib/python2.5/copy.py in _deepcopy_list(x, memo)
    225     memo[id(x)] = y
    226     for a in x:
--> 227         y.append(deepcopy(a, memo))
    228     return y
    229 d[list] = _deepcopy_list
/usr/local/python-2.5.1/lib/python2.5/copy.py in deepcopy(x, memo, _nil)
    187                             raise Error(
    188                                 "un(deep)copyable object of type %s" % cls)
--> 189                 y = _reconstruct(x, rv, 1, memo)
    190
    191     memo[d] = y
/usr/local/python-2.5.1/lib/python2.5/copy.py in _reconstruct(x, info, deep, memo)
    320     if deep:
    321         args = deepcopy(args, memo)
--> 322     y = callable(*args)
    323     memo[id(x)] = y
    324     if listiter is not None:
/usr/local/python-2.5.1/lib/python2.5/copy_reg.py in __newobj__(cls, *args)
     90
     91 def __newobj__(cls, *args):
---> 92     return cls.__new__(cls, *args)
     93
     94 def _slotnames(cls):
<type 'exceptions.TypeError'>: __new__() takes exactly 3 arguments (1 given)

----- Original Message ----
From: Chris Rebert <clp2 at rebertia.com>
To: srinivasan srinivas <sri_annauni at yahoo.co.in>
Cc: python-list at python.org
Sent: Thursday, 8 January, 2009 1:56:27 PM
Subject: Re: How to deepcopy a list of user defined lists?

On Wed, Jan 7, 2009 at 11:59 PM, srinivasan srinivas
<sri_annauni at yahoo.co.in> wrote:
> Hi,
> I have a class which is a subclass of builtin-type list.
>
> #------------------------------------------------------------------------------
> class clist(list):
>    def __new__(cls, values, ctor):
>        val = []
>        for item in values:
>            item = ctor(item)
>            val.append(item)
>
>        self = list.__new__(cls, val)
>        self.__values = val
>        self.__ctor = ctor
>        return self
> #-----------------------------------------------------------------------------------
>
> I have a list of clists, say c1 = [clist1, clist2, clist3]
> How do i deepcopy this list? I tried using copy.deepcopy() method. But i got some errors. Please suggest me.

And those errors are? Please include a full Traceback.

Cheers,
Chris

-- 
Follow the path of the Iguana...
http://rebertia.com



      Check out the all-new Messenger 9.0! Go to http://in.messenger.yahoo.com/



More information about the Python-list mailing list