python __init__ method in inherited class

前端 未结 6 1833
深忆病人
深忆病人 2021-02-07 01:36

I would like to give a daughter class some extra attributes without having to explicitly call a new method. So is there a way of giving the inherited class an __init__

6条回答
  •  遇见更好的自我
    2021-02-07 02:16

    As far as I know that's not possible, however you can call the init method of the superclass, like this:

    class inheritedclass(initialclass):
        def __init__(self):
            initialclass.__init__(self)
            self.attr3 = 'three'
    

提交回复
热议问题