我试图执行此代码之前引用,UnboundLocalError:局部变量“Z”分配
def getInterPropreCat(h,cat):
for txt in h:
if txt['Categorie'] == cat:
z=[txt['Max'],txt['Min']]
g=getListZERO(h,cat)
for text in g:
z = getInterPropore(text['Min'],text['Max'],z[1],z[0])
# print(y)
return z
和我做一个测试:
print(getInterPropreCat(h,cat1))
这是给我一个结果,那么我做一个循环让所有类别的结果:
for txt in CatList:
getInterPropreCat(h,txt)
,我有这样的错误:
z = getInterPropore(text['Min'],text['Max'],z[1],z[0])
UnboundLocalError:局部变量 'Z' 分配
任何帮助之前引用?
如果'h'中的字符没有匹配的'Categorie',那么'z'永远不会被设置。 – chepner
你必须知道我的函数给出[3000.0,1746.65],这对我很有用......但是当我在CatList中使用txt时:getInterPropreCat(h,txt)..给出错误 –
提供一个具体的例子(CatList:getInterPropreCat(h,txt))中的'CatList'和'h'的值会产生错误。 – chepner