相关疑难解决方法(0)

super()和@staticmethod交互

super()是不是要用于staticmethods?

当我尝试类似的东西

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
Run Code Online (Sandbox Code Playgroud)

我收到以下错误

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'
Run Code Online (Sandbox Code Playgroud)

如果我将staticmethods更改为classmethods并将类实例传递给super(),那么一切正常.我在这里不正确地调用超级(类型)还是有些东西我不见了?

python static-methods super python-2.7

42
推荐指数
2
解决办法
1万
查看次数

标签 统计

python ×1

python-2.7 ×1

static-methods ×1

super ×1