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

后端 未结 4 1972
既然无缘
既然无缘 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:09

    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 = image
    
    class Eye(Frame):
        def __init__(self, image):
            super(Eye, self).__init__(image)
            self.some_other_defined_stuff()
    

提交回复
热议问题