【发布时间】:2011-08-09 09:35:00
【问题描述】:
我知道 C++ 和 Java,但我不熟悉 Pythonic 编程。所以也许这是我想要做的不好的风格。
考虑闲置的例子:
class foo:
def a():
__class__.b() # gives: this is foo
bar.b() # gives: this is bar
foo.b() # gives: this is foo
# b() I'd like to get "this is bar" automatically
def b():
print("this is foo")
class bar( foo ):
def b( ):
print("this is bar")
bar.a()
请注意,我没有使用self 参数,因为我没有尝试创建类的实例,因为我的任务不需要。我只是想以一种可以覆盖该函数的方式引用一个函数。
【问题讨论】:
标签: python oop inheritance class-method static-functions