当前位置: 代码迷 >> 综合 >> 解决问题python:SyntaxError: unexpected EOF while parsing
  详细解决方案

解决问题python:SyntaxError: unexpected EOF while parsing

热度:36   发布时间:2024-03-07 03:28:26.0
# 原因,使用eval时,数据为空报错
eval("")
# 报错信息
Traceback (most recent call last):File "<input>", line 1, in <module>File "<string>", line 0^
SyntaxError: unexpected EOF while parsingimport ast
ast.literal_eval('')
# 报错信息
Traceback (most recent call last):File "<input>", line 1, in <module>File "/opt/nsfocus/espc/deps/env/lib/python2.7/ast.py", line 49, in literal_evalnode_or_string = parse(node_or_string, mode='eval')File "/opt/nsfocus/espc/deps/env/lib/python2.7/ast.py", line 37, in parsereturn compile(source, filename, mode, PyCF_ONLY_AST)File "<unknown>", line 0^
SyntaxError: unexpected EOF while parsing

解决办法:使用函数时,对数据做不为空校验

  相关解决方案