[英]UnboundLocalError: local variable referenced before assignment whit global
I receive:我收到:
UnboundLocalError: local variable 'ImgY' referenced before assignment
When I do something like this:当我做这样的事情时:
q = 0
def a():
print(q)
while True:
com = input("")
if com == "":
a()
else:
q = com
The piece "a()":片段“a()”:
def df():
global deas
if vs != 1:
if deas == 0:
deas = 1
for a in range(ImgY):
for s in range(ImgX):
corrente[num[a] + num[s]] = " "
else:
if imp == 1:
ImgX = q[0:1]
ImgY = q[2:3]
for a in range(int(ImgY)):
for s in range(int(ImgX)):
corrente[num[a] + num[s]] = q[s+5]
else:
if deas == 0:
deas = 1
for a in range(ImgY):
for s in range(ImgX):
corrente[num[a] + num[s]] = " "
I don't understand why since ImgY is a global variable and is defined with "ImgY = 30" on the line below (the global) The rest here我不明白为什么因为 ImgY 是一个全局变量并且在下面的行(全局)中用“ImgY = 30”定义这里的 rest
Inside the snippet片段内
def df():
global deas
if vs != 1:
if deas == 0:
deas = 1
for a in range(ImgY):
for s in range(ImgX):
corrente[num[a] + num[s]] = " "
ImgY/ImgX don't seem to be assigned. ImgY/ImgX 似乎没有被分配。 So if they are global variables, try with:
因此,如果它们是全局变量,请尝试:
def df():
global deas,ImgY,ImgX
if vs != 1:
if deas == 0:
deas = 1
for a in range(ImgY):
for s in range(ImgX):
corrente[num[a] + num[s]] = " "
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.