我知道 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
参数,因为我没有尝试创建类的实例,因为不需要我的任务。我只是想以一种可以覆盖该函数的方式引用一个函数。