Python 2.x super __init__ inheritance doesn't work when parent doesn't inherit from object
There are two errors here:
super()
only works for new-style classes; useobject
as a base class forFrame
to make it use new-style semantics.You still need to call the overridden method with the right arguments; pass in
image
to the__init__
call.
So the correct code would be:
class Frame(object): def __init__(self, image): self.image = imageclass Eye(Frame): def __init__(self, image): super(Eye, self).__init__(image) self.some_other_defined_stuff()
Frame
must extend object
because only the new style classes support super
call you make in Eye
like so:
class Frame(object): def __init__(self, image): self.image = imageclass Eye(Frame): def __init__(self, image): super(Eye, self).__init__(image) self.some_other_defined_stuff()
Please write :__metaclass__ = type
at the top of the code then we can Access super class
__metaclass__ = typeclass Vehicle: def start(self): print("Starting engine") def stop(self): print("Stopping engine") class TwoWheeler(Vehicle): def say(self): super(TwoWheeler,self).start() print("I have two wheels") super(TwoWheeler,self).stop() Pulsar=TwoWheeler()Pulsar.say()