val = 9 def test(flag): if flag: val = 1 else: print("test") return val if __name__ == '__main__': ret = test(0) print(ret) 运行如下: linux@linux-desktop:~$ python3.3 test.py fuckTraceback (most recent call last): File "test.py", line 10,…
Issue: When you install RDO stack on CentOS, you may encounter following error. Error: [root@localhost ~]# packstack --allinone ERROR:root:Failed to load plugin from file prescript_000.py ERROR:root:Traceback (most recent call last): File "/usr/lib/p…
出现UnboundLocalError: local variable ‘a’ referenced before assignment异常的情况与解决方法字面意思:局部变量赋值前被引用原因:局部变量与全局变量同名例: a = def func(): a += print(a) func() 解决方法:1.使局部变量与全局变量不同名 a = def func(): b = a + print(b) func() 2.使用global关键字 a = def func(): global a a +…