Suppose I have a class called Animal and a subclass called Dog. How can I access the Animal’s unicode definition from the Dog class?
class Animal:
def __unicode__(self):
return 'animal'
class Dog(Animal):
def __unicode__(self):
return 'this %s is a dog' % (I want to get the Animal's __unicode__ here)
Since you’re implementing old-style classes in Python 2, you can only access the methods of your base class by their qualified names:
However, if you modify your base class so it becomes a new-style class, then you can use super():
Note that all classes are new-style classes in Python 3, so
super()can always be used when running that version.