Quicker way to copy()?

Discussion in 'Python' started by has, Jun 9, 2004.

  1. has

    has Guest

    I'm wondering if the following code is acceptable for shallow copying
    instances of new-style classes:

    class clone(object):
    def __init__(self, origObj):
    self.__dict__ = origObj.__dict__.copy()
    self.__class__ = origObj.__class__


    a = SomeClass()
    aCopy = clone(a)

    I've been using the copy module's copy() function till now, but this
    is affecting performance in heavy use so I'd really like to optimise
    it out. (This is for HTMLTemplate, which does _lots_ of cloning.) The
    above 'clone' seems to work okay OMM (MacPython 2.3.3), but I'm not
    completely up on the inner workings of Python classes so if anyone can
    tell me whether or not I've missed anything it'd be a big help.
    Thanks.
    has, Jun 9, 2004
    #1
    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. Carlo Filippini
    Replies:
    3
    Views:
    397
  2. Helixpoint
    Replies:
    4
    Views:
    411
    John Saunders
    Aug 1, 2003
  3. Mark
    Replies:
    3
    Views:
    2,038
    John Saunders
    Nov 12, 2004
  4. Tarren
    Replies:
    2
    Views:
    10,256
    Brock Allen
    Sep 29, 2005
  5. Quicker way for DOM?

    , May 31, 2007, in forum: Javascript
    Replies:
    7
    Views:
    105
Loading...

Share This Page