SyntaxWarning: name 'x' is assigned to before global declaration global color Python
2018-03-27 11:00
806 查看
SyntaxWarning: name 'x' is assigned to before global declaration global color Python
这种报错很大原因是在同一个函数重复使用了global 声明举个例子x = 0
def func(a, b, c):
if a == b:
global x
x = 10
elif b == c:
global x
x = 20在每次使用变量之前,不要立即进行全局声明,只需要在函数开始处使用它一次就行了,下面是正确的写法x = 0
def func(a, b, c):
global x # <- here
if a == b:
x = 10
elif b == c:
x = 20参考连接:http://effbot.org/zone/syntaxwarning-name-assigned-to-before-global-declaration.htm
相关文章推荐
- Python错误 SyntaxWarning: name 'xxx' is assigned to before global declaration
- [ISSUE]SyntaxWarning: name 'xxx' is assigned to before global declaration
- 关于python-NameError: global name 'platform' is not defined
- Python 出现错误 SNIMissingWarning: An HTTPS request has been made, but the SNI (Subject Name Indication) extension to TLS is not available on this platform.
- fields must be fully assigned before control is returned to the caller解决方案
- 执行python文件报global name 'os' is not defined
- python2.7以下出 NameError: global name 'FileNotFoundError' is not defined的解决方案
- Python使用Tkinter错误,NameError: global name 'TOP' is not defined
- Python error: Microsoft Visual C++ 9.0 is required (Unable to find vcvarsall.bat)解决方案
- Python3下的ssl certificate:Can't connect to HTTPS URL because the SSL module is not available.问题解决
- jieba分词,导入新词库出现的global name f_name is not defined
- Warning: The name 'layoutWidget' (QWidget) is already in use, defaulting to 'layoutWidget1'.
- 数据源没发现! Name [jdbc/mysql5] is not bound in this Context. Unable to find [jdbc].
- C编译问题: declaration is incompatible with previous "FuncName" (declared at line XXX)
- python3.6.1安装失败:Service Pack 1 is required to continue installation
- Python 解决 :NameError: name 'reload' is not defined 问题
- Python: Windows下pip安装库出错:Microsoft Visual C++ 9.0 is required < Unable to find vcvarsall.bat
- IE8 中"HTML Parsing Error:Unable to modify the parent container element before the child element is closed"错误
- HTML Parsing Error: Unable to modify the parent container element before the child element is closed
- [python] pandas.Series.plot( )报错“name _converter is not defined”