Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?
I mean, something like Apache Commons' PropertyUtilsBean.copyProperties()
Use Python's vars() to Print an Object's Attributes The dir() function, as shown above, prints all of the attributes of a Python object.
To get a fully independent copy of an object you can use the copy. deepcopy() function.
In Python, we use = operator to create a copy of an object. You may think that this creates a new object; it doesn't. It only creates a new variable that shares the reference of the original object.
Try destination.__dict__.update(source.__dict__)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With