由于
test()不知道是谁
abc,因此
NameError: global name 'abc' is notdefined您看到的味精应该在调用时发生
b.test()(调用
b.abc()很好),请将其更改为:
class a: def abc(self): print "haha" def test(self): self.abc() # abc()b = a()b.abc() # 'haha' is printedb.test() # 'haha' is printed

由于
test()不知道是谁
abc,因此
NameError: global name 'abc' is notdefined您看到的味精应该在调用时发生
b.test()(调用
b.abc()很好),请将其更改为:
class a: def abc(self): print "haha" def test(self): self.abc() # abc()b = a()b.abc() # 'haha' is printedb.test() # 'haha' is printed