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.
You can just define
__init__in the subclass and callsuperto call the parents’__init__methods appropriately:If you’re still on Python 2.x, make sure the base class is a subclass of
object, assuperwon’t work with old-style classes: