【发布时间】:2019-03-30 10:59:13
【问题描述】:
我正在编写一个 python 类并试图从该类中的另一个函数调用一个函数,但我遇到了一个错误。NameError: name 'bobfunction' is not defined。我对课堂的调用有效,甚至对方法/函数作业的调用也有效。当job 尝试调用bobfunction 时,我收到错误消息。删除对bobfunction 的调用有效。那么如何从 job 函数中调用 bobfunction 呢?
class stuff():
def __init__(self):
#setup stuff
def bobfunction(self,junk):
print("should work")
return ''
def job(self,data):
bobfunction('test data')
return 'other junk'
【问题讨论】:
-
您的缩进似乎偏移了。工作职能中的
def应与bobfunction 中的def对齐
标签: python-3.x class methods