超能实现什么

What does super achieve

这是构建自定义keras层的代码

class MyLayer(Layer):

    def __init__(self, output_dim, **kwargs):
        self.output_dim = output_dim
        super(MyLayer, self).__init__(**kwargs)

super 在这里做什么,绝对有必要吗?

欢迎使用 Whosebug。超-

“.. returns a proxy object that delegates method calls to a parent or sibling class of type. This is useful for accessing inherited methods that have been overridden in a class. The search order is same as that used by getattr() except that the type itself is skipped.”

特别是在 Keras 的情况下,基础层执行 class 的所有基础操作,如源代码中所述,

https://github.com/keras-team/keras/blob/master/keras/engine/base_layer.py#L21

您可以在

阅读更多关于 Super 和 Inheritance 的信息

https://realpython.com/python-super/