470,841 Members | 905 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,841 developers. It's quick & easy.

Quicker way to copy()?

has
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.
Jul 18 '05 #1
0 849

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

42 posts views Thread by Edward Diener | last post: by
13 posts views Thread by Chris Mantoulidis | last post: by
4 posts views Thread by Legendary Pansy | last post: by
1 post views Thread by edwilli | last post: by
5 posts views Thread by Benson | last post: by
20 posts views Thread by puzzlecracker | last post: by
reply views Thread by mihailmihai484 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.