I have created a base class:
class Thing():
def __init__(self, name):
self.name = name
I want to extend the class and add to the init method so the that SubThing
has both a name
and a time
property. How do I do it?
class SubThing(Thing):
# something here to extend the init and add a "time" property
def __repr__(self):
return '<%s %s>' % (self.name, self.time)
Any help would be awesome.
SubThing
insuper
, you can dosuper(self.__class__, self).__init__(*args, **kwargs)
. This also works with dynamically created classes usingtype()
. – Fatma