copy an object

Y

Yuval

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.
 
J

John J. Lee

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top