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)
...
>
[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
[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):
...
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
[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 '
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