Since test()
doesn't know who is abc
, that msg NameError: global name 'abc' is not defined
you see should happen when you invoke b.test()
(calling b.abc()
is fine), change it to:
class a:
def abc(self):
print "haha"
def test(self):
self.abc()
# abc()
b = a()
b.abc() # 'haha' is printed
b.test() # 'haha' is printed
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…