【发布时间】:2015-01-03 11:24:59
【问题描述】:
super() 不应该与静态方法一起使用吗?
当我尝试类似的东西时
class First(object):
@staticmethod
def getlist():
return ['first']
class Second(First):
@staticmethod
def getlist():
l = super(Second).getlist()
l.append('second')
return l
a = Second.getlist()
print a
我收到以下错误
Traceback (most recent call last):
File "asdf.py", line 13, in <module>
a = Second.getlist()
File "asdf.py", line 9, in getlist
l = super(Second).getlist()
AttributeError: 'super' object has no attribute 'getlist'
如果我将静态方法更改为类方法并将类实例传递给 super(),则一切正常。我在这里错误地调用 super(type) 还是我遗漏了什么?
【问题讨论】:
标签: python python-2.7 static-methods super