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

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

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:
    5,215
    Tris Orendorff
    Apr 29, 2004
  2. Tony Johansson

    deep and shallow copy

    Tony Johansson, May 19, 2005, in forum: C++
    Replies:
    5
    Views:
    10,083
    Rapscallion
    May 19, 2005
  3. Alex
    Replies:
    2
    Views:
    1,611
  4. Replies:
    1
    Views:
    684
    Victor Bazarov
    Jun 24, 2005
  5. Replies:
    8
    Views:
    491
    benben
    Jun 24, 2006
  6. Replies:
    26
    Views:
    2,574
    Roland Pibinger
    Sep 1, 2006
  7. shuisheng
    Replies:
    4
    Views:
    1,001
    Uenal S. Mutlu
    Dec 17, 2006
  8. Replies:
    2
    Views:
    2,651
    John Harrison
    May 26, 2007
Loading...