Alex Rivera | Logout

Copy constructor in python?

Asked 2009-08-06T20:16:48.117
132

Is there a copy constructor in python ? If not what would I do to achieve something similar ?

The situation is that I am using a library and I have extended one of the classes there with extra functionality and I want to be able to convert the objects I get from the library to instances of my own class.

Edit
Report

1 Answer

15

For your situation, I would suggest writing a class method (or it could be a static method or a separate function) that takes as an argument an instance of the library's class and returns an instance of your class with all applicable attributes copied over.

answered 2009-08-06T20:31:14.887

Your Answer