Re: how to copy a Python object

2006-02-07 Thread Alex Martelli
Schüle Daniel <[EMAIL PROTECTED]> wrote: ... > >>> class X(object): > ... def __init__(self,lst): > ... self.lst = lst > ... def copy(self): > ... return X(self.lst[:]) > ... def __str__(self): > ... return "lst has id %i" % id(self.lst) ... >

Re: how to copy a Python object

2006-02-07 Thread Juho Schultz
[EMAIL PROTECTED] wrote: > Already thanks for the reply, > > but how to write your own copy operator? Won't you always be passing > referrences to new_obj? > If you need to modify the behaviour of copy or deepcopy, you can give your class __copy__ and __deepcopy__ methods. Then copy.copy and c

Re: how to copy a Python object

2006-02-07 Thread Schüle Daniel
[EMAIL PROTECTED] wrote: > Already thanks for the reply, > > but how to write your own copy operator? Won't you always be passing > referrences to new_obj? for example this would work >>> class X(object): ... def __init__(self,lst): ... self.lst = lst ... def copy(self): ...

Re: how to copy a Python object

2006-02-07 Thread mitsura
Already thanks for the reply, but how to write your own copy operator? Won't you always be passing referrences to new_obj? -- http://mail.python.org/mailman/listinfo/python-list

Re: how to copy a Python object

2006-02-07 Thread [EMAIL PROTECTED]
[EMAIL PROTECTED] a écrit : > Hi, > > I am new to Python and OO programming. > I need to copy a Python object (of a class I made myself). > new_obj = old_object doesn't seem to work since apparently new_obj is > then a referrence to old_obj. it is > > I found out that there is a module called '

how to copy a Python object

2006-02-07 Thread mitsura
Hi, I am new to Python and OO programming. I need to copy a Python object (of a class I made myself). new_obj = old_object doesn't seem to work since apparently new_obj is then a referrence to old_obj. I found out that there is a module called 'copy' that allows you to do a shallow or a deep copy