# 原因,使用eval时,数据为空报错
eval("")
# 报错信息
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "<string>", line 0
^
SyntaxError: unexpected EOF while parsing
import ast
ast.literal_eval('')
# 报错信息
Traceback (most recent call last):
File "<input>", line 1, in <module>
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 "<unknown>", line 0
^
SyntaxError: unexpected EOF while parsing
解决办法:使用函数时,对数据做不为空校验