调用函数时,输入未定义的参数,如何用try except打印出异...
user_list = [["Account number","Currency","Balance"],["001-987654-003","USD",1300.72],
["001-919202-100","EUR",105.01],
["001-905700-100","EUR",305.00],
["001-908415-307","CHF",20804.98],
["011-974777-200","PLN",208.15],
["001-931654-001","USD",450.7]]
def vlookup(lookupvalue,lookuplist,col_index):
try:
lookuplist = user_list
except Exception as e:
print(str(e))
else:
length1 =len(lookuplist)
length2 =len(lookuplist)
for j in range(length2):
if lookupvalue == lookuplist:
if col_index - 1 in range(length1):
return print(lookuplist)
else:
return print('Out of scope')
else:
continue
return print('Not found')vlookup("001-919202-100",otheruserlist, 2)
Traceback (most recent call last):
File "C:\Users\Kevin Sun\untitled0.py", line 59, in <module>
vlookup("001-919202-100",otheruserlist, 2)
NameError: name 'otheruserlist' is not defined
你这个otheruserlist不是未定义函数参数,是otheruserlist这个变量没有定义,你得先给它赋值才能在函数vlookup中传递。 这个不是运行时异常。。你编译都通过不了。你使用变量之前要先声明它。
name 'otheruserlist' is not defined
页:
[1]