class assignment copy

Bill Scherer scherbi at bam.com
Mon Jan 3 14:58:00 EST 2000


You need the copy module. see

http://www.python.org/doc/current/lib/module-copy.html


tiddlerdeja at my-deja.com wrote:

> Sorry for the lame question.
>
> If I have a class Foo:
>
> class Foo:
>     def __init__(self):
>         self.bar = 1
>
> If I create one instance of the class:
>
> x = Foo()
>
> How do I make a copy of x?
>
> y = x
>
> Just makes y refer to x, so if I change bar on y the value is also
> changed on x.
>
> I realise this is a lame question, I just couldn't find any python
> material on this.
>
> Do I need to create some copy constructor on the class?
>
> Any help appreciated.
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
> --
> http://www.python.org/mailman/listinfo/python-list

--
William K. Scherer
Sr. Member of Applications Staff
Bell Atlantic Mobile
914 365 7265


-------------- next part --------------
A non-text attachment was scrubbed...
Name: scherbi.vcf
Type: text/x-vcard
Size: 226 bytes
Desc: Card for Bill Scherer
URL: <http://mail.python.org/pipermail/python-list/attachments/20000103/e2632bd1/attachment.vcf>


More information about the Python-list mailing list