我想给家长打电话call来自继承类的方法
代码看起来像这样
#!/usr/bin/env python
class Parent(object):
def __call__(self, name):
print "hello world, ", name
class Person(Parent):
def __call__(self, someinfo):
super(Parent, self).__call__(someinfo)
p = Person()
p("info")
我得到,
File "./test.py", line 12, in __call__
super(Parent, self).__call__(someinfo)
AttributeError: 'super' object has no attribute '__call__'
我不明白为什么,有人可以帮我吗?
The super
函数取derivedclass 作为其第一个参数,而不是基类。
super(Person, self).__call__(someinfo)
如果您需要使用基类,可以直接执行(但要注意,这会破坏多重继承,因此除非您确定这就是您想要的,否则不应该这样做):
Parent.__call__(self, someinfo)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)