根据http://docs.python.org/2/library/functions.html#super,
如果省略第二个参数,则返回的超级对象是未绑定的.
哪个是超级(类型).
我想知道什么是无限的,什么时候有限.
这按预期工作:
>>> class Foo(object):
... @classmethod
... def hello(cls):
... print 'hello, foo'
...
>>> class Bar(Foo):
... @classmethod
... def hello(cls):
... print 'hello, bar'
... super(Bar, cls).hello()
...
>>> b = Bar()
>>> b.hello()
hello, bar
hello, foo
Run Code Online (Sandbox Code Playgroud)
我也可以显式调用基类:
>>> class Bar(Foo):
... @classmethod
... def hello(cls):
... print 'hello, bar'
... Foo.hello()
...
>>> b = Bar()
>>> b.hello()
hello, bar
hello, foo
Run Code Online (Sandbox Code Playgroud)
我想知道为什么我不能省略第一个参数super,像这样:
>>> class Bar(Foo):
... @classmethod
... def hello(cls):
... print 'hello, …Run Code Online (Sandbox Code Playgroud)