Call constructor of cls object in Python -
i trying call constructor of class
object in python. managed work using following few lines:
obj = cls.__new__(cls) n = (list of attribute names) v = (list of attribute values) s in n: setattr(obj, s, v[s])
i wondering if there way directly insert attribute value + name pairs constructor, cause arguments ignored if call following:
obj = cls.__new__(cls, v)
p.s.: using python3
the class looks similar this:
class inheritingclass(baseclass): def __init__(self, basic_attribute, another_attribute=none): super().__init__(basic_attribute=basic_attribute) self.another_attribute= another_attribute class baseclass: def __init__(self, basic_attribute=1): self.basic_attribute= basic_attribute
so nothing special there
__init__
constructor of python class instead of __new__
. refer pythons use of new , init more information.
Comments
Post a Comment