copy an object

Discussion in 'Python' started by Yuval, Jun 26, 2003.

  1. Yuval

    Yuval Guest

    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.
    Yuval, Jun 26, 2003
    #1
    1. Advertising

  2. Yuval

    John J. Lee Guest

    (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
    John J. Lee, Jun 26, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jazz
    Replies:
    3
    Views:
    748
    Kristian Bisgaard Lassen
    Oct 28, 2003
  2. VisionSet
    Replies:
    8
    Views:
    4,873
    Tris Orendorff
    Apr 29, 2004
  3. Alex
    Replies:
    2
    Views:
    1,202
  4. Replies:
    26
    Views:
    2,083
    Roland Pibinger
    Sep 1, 2006
  5. Rahul
    Replies:
    2
    Views:
    742
Loading...

Share This Page