How to copy all properties of an object to another object, in Python?
Try destination.__dict__.update(source.__dict__)
.
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.