Python - 覆盖静态方法

tho*_*lin 4 python

如何覆盖staticmethod并保持静态?

In [6]: class Foo(object):
   ...:     @staticmethod
   ...:     def foo(a, b):
   ...:         print a + b
   ...:         
   ...:         

In [7]: Foo.foo
Out[7]: <function foo at 0x86a1a74>

In [8]: class Bar(Foo):
   ...:     def foo(a, b):
   ...:         print a - b
   ...:         
   ...:         

In [9]: Bar.foo
Out[9]: <unbound method Bar.foo>
Run Code Online (Sandbox Code Playgroud)

我用staticmethod试过装饰Bar's foo,它很有效.但我每次子类化时都要装饰它.

Thi*_*ter 5

这就是你应该怎么做的.在其他编程语言中,您也必须static每次都使用关键字.