|
test = "全局"
def testnamespace1(test):
print (test)
test = "函数内部"
def testnamespage2():
print (test)
test = "函数的函数内部"
print(test)
return testnamespage2
t = testnamespace1(test)
t()
看似没问题,实则无法运行,会有异常UnboundLocalError: local variable 'test' referenced before assignment
如果注释掉namespage2 里面的print(test)就可以顺利执行,
想请问大佬们,这是怎么回事,一个print语句怎么能报错呢?
|
|