我用这个构造函数编写一个Python类:
#constuctor
def __init__(self, initPt_=[1,1],fun_=Optim_tests.peaks,NITER_=30,alpha_=0.7,NMAX_=5000,FTOL_=10**(-10)):
self.initPt = initPt_
self.fun = fun_
self.alpha = alpha_
self.ITER = NITER_
self.NMAX = NMAX_
self.FTOL = FTOL_
以及定义两个成员函数:
^{pr2}$调用第二个函数时,发生错误:
NameError: global name 'buildSimplex' is not defined
你有线索吗?在
乍一看,我会说这是一个识别问题,但是你需要提供一个更具体的答案的实际代码。在
我之所以这么说是因为你犯了错误。如果正确地声明了类,并尝试调用未定义实例的方法,那么实际上应该得到一个:
AttributeError: A instance has no attribute 'xxxx'
。如果方法在类中声明,则不需要关心定义方法的顺序。请参见下面的met1
和met4
的示例例如:
您的错误
NameError: global name 'buildTool1' is not defined
表示您试图访问变量buildTool1
,但它没有在本地或全局中定义。在请检查一下这个
相关问题 更多 >
编程相关推荐