Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   copy an object (http://www.velocityreviews.com/forums/t318856-copy-an-object.html)

Yuval 06-26-2003 12:44 AM

copy an object
 
I have an object of a class I wrote myself, and now I want to copy it.
How do I do it? The reason I want to copy it is because if I simply
use copied_object=existing_object, when I later change
"copied_object", "existing_object" is changed as well, and I dont want
it to happen.

Thanks.

John J. Lee 06-26-2003 01:23 AM

Re: copy an object
 
yuvalfeld@hotmail.com (Yuval) writes:

> I have an object of a class I wrote myself, and now I want to copy it.

[...]

john[0]$ python
Python 2.3b1 (#2, May 2 2003, 11:43:06)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import copy
>>> help(copy)


>>> # also...
>>> lst = [1,2,3]
>>> newlst = lst[:]
>>> newlst[1] = "spam"
>>> print newlst

[1, 'spam', 3]
>>> print l

[1, 2, 3]


John


All times are GMT. The time now is 01:19 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.