Python 2.x super __init__ inheritance doesn't work when parent doesn't inherit from object

后端 未结 4 1974
既然无缘
既然无缘 2020-12-14 16:46

I have the following Python 2.7 code:

class Frame:
    def __init__(self, image):
        self.image = image

class Eye(Frame):
    def __init__(self, image)         


        
4条回答
  •  不知归路
    2020-12-14 17:11

    Please write :__metaclass__ = type at the top of the code then we can Access super class

    __metaclass__ = type
    class 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()
    

提交回复
热议问题