在父函数中调用子函数的成员函数, 遇到个问题, 代码如下
class Foo(object):
def __init__(self):
self._func = None
def callDerivedFunc(self):
# self._func() # wrong
method = self._func
method(self) # right
class Bar(Foo):
def __init__(self):
super(Foo, self).__init__()
self._func = Bar.hello
def hello(self):
print 'Hello'
bar = Bar()
bar.callDerivedFunc()
一直以为这两种调用方法是一样的, 求教两者区别的详细解释
class Foo(object):
def __init__(self):
self._func = None
def callDerivedFunc(self):
# self._func() # wrong
method = self._func
method(self) # right
class Bar(Foo):
def __init__(self):
super(Foo, self).__init__()
self._func = Bar.hello
def hello(self):
print 'Hello'
bar = Bar()
bar.callDerivedFunc()
一直以为这两种调用方法是一样的, 求教两者区别的详细解释