Sal
Peter Hoffmann Director Data Engineering at Blue Yonder. Python Developer, Conference Speaker, Mountaineer

How to copy all properties of an object to another object, in Python?

This my Answer to the stackoverflow question: How to copy all properties of an object to another object, in Python?:

If your class does not modify _ _ getitem _ _ or _ _ setitem _ _ for special attribute access all your attributes are stored in _ _ dict _ _ so you can do:

 nobj.__dict__ = oobj.__dict__.copy()    # just a shallow copy

If you use python properties you should look at inspect.getmembers() and filter out the ones you want to copy.