我試圖執行此代碼之前引用,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