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()
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If your class does not modify
__getitem__or__setitem__for special attribute access all your attributes are stored in__dict__so you can do:If you use python properties you should look at
inspect.getmembers()and filter out the ones you want to copy.