Quick shallow-copy idiom

Discussion in 'Python' started by Lawrence D'Oliveiro, Sep 19, 2007.

  1. y = type(x)(x)
     
    Lawrence D'Oliveiro, Sep 19, 2007
    #1
    1. Advertising

  2. Lawrence D'Oliveiro

    paulhankin Guest

    On Sep 19, 10:48 am, Lawrence D'Oliveiro <l...@geek-
    central.gen.new_zealand> wrote:
    > y = type(x)(x)


    Nice trick, but is it better than the explicit:
    y = copy.copy(x)

    (I think not, because copy.copy works for example, on classes
    which take more than one argument to their constructor).

    --
    Paul Hankin
     
    paulhankin, Sep 19, 2007
    #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. VisionSet
    Replies:
    8
    Views:
    4,902
    Tris Orendorff
    Apr 29, 2004
  2. Alex
    Replies:
    2
    Views:
    1,232
  3. Replies:
    1
    Views:
    544
    Victor Bazarov
    Jun 24, 2005
  4. Replies:
    26
    Views:
    2,118
    Roland Pibinger
    Sep 1, 2006
  5. shuisheng
    Replies:
    4
    Views:
    838
    Uenal S. Mutlu
    Dec 17, 2006
Loading...

Share This Page