6
我对python比较陌生,我遇到了一些与命名空间有关的问题。python类中函数名未定义
class a:
def abc(self):
print "haha"
def test(self):
abc()
b = a()
b.abc() #throws an error of abc is not defined. cannot explain why is this so
它正在工作,'class a'的函数'abc()'被其实例调用。 – 2015-03-02 08:06:11
我认为不是'b.abc()',你调用'b.test()'应该抛出错误。这是因为你应该使用类实例的引用来调用'abc()'。只需在'class a'的'test()'函数中用'self.abc()'替换'abc()'。 – 2015-03-02 08:10:35