我收到以下错误:
UnboundLocalError: local variable 'current_uarfcn' referenced before assignment
但是我不知道为什么,我以与该变量相同的方式声明它ran_update_uarfcn
并且该变量工作正常。有任何想法吗?
current_uarfcn = ""
ran_update_uarfcn = ""
def ran_network_listen(access_point_id, mode):
def set_current_uarfcn(value):
global current_uarfcn
global ran_update_uarfcn
current_uarfcn = value
ran_update_uarfcn = "upd ap" + " " + access_point_id + " " + "uarfcn=" + current_uarfcn
set_current_uarfcn("11000")
print ran_update_uarfcn
print current_uarfcn
return
编辑:堆栈跟踪
Traceback (most recent call last):
File "/a/b.py", line 460, in <module>
ran_network_listen(ap_id, mode)
File "/a/b.py", line 97, in ran_network_listen
print current_uarfcn
UnboundLocalError: local variable 'current_uarfcn' referenced before assignment
像这样调用:
# Network Listen
if args.ap_id:
ap_id = args.ap_id[0]
mode = None
if len(args.ap_id) == 2:
mode = args.ap_id[1]
ran_network_listen(ap_id, mode)