Working on a class that I would use multiple constructors in C++ since I have different ways of creating the data. Tried this in python by defining multiple __init__ methods but to no avail, it seems to only find the second one. So I have:
Now my class is way more complex then that, but I just want multiple __init__ methods, with different signatures, to insantite my objects. When i try to use the first one it says "TypeError: __init__() takes exactly 2 arguments (3 given)" using the second version of __init__ does work. Thoughts?
Code:
class myclass: __init__ (self, mystring1, mystring2) self.name = mystring1 self.value = mystring2 __init__ (self, xmldoc): <some code to parse the XML into my attrs>
Now my class is way more complex then that, but I just want multiple __init__ methods, with different signatures, to insantite my objects. When i try to use the first one it says "TypeError: __init__() takes exactly 2 arguments (3 given)" using the second version of __init__ does work. Thoughts?
Comment