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

# 原因,使用eval时,数据为空报错
eval("")
# 报错信息
Traceback (most recent call last):
  File "", line 1, in 
  File "", line 0
    
   ^
SyntaxError: unexpected EOF while parsing



import ast
ast.literal_eval('')
# 报错信息
Traceback (most recent call last):
  File "", line 1, in 
  File "/env/lib/python2.7/ast.py", line 49, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/env/lib/python2.7/ast.py", line 37, in parse
    return compile(source, filename, mode, PyCF_ONLY_AST)
  File "", line 0
    
   ^
SyntaxError: unexpected EOF while parsing

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

你可能感兴趣的:(问题解决,python)