ast.literal_eval(node_or_string) Safely evaluate an expression node or
a Unicode or Latin-1 encoded string containing a Python literal or
container display. The string or node provided may only consist of the
following Python literal structures: strings, numbers, tuples, lists,
dicts, booleans, and None.
This can be used for safely evaluating strings containing Python
values from untrusted sources without the need to parse the values
oneself. It is not capable of evaluating arbitrarily complex
expressions, for example involving operators or indexing.
可以使用^{} 将该字符串转换为如下python对象:
ast
代表抽象语法树。literal_eval()
比eval()
安全得多。在引用官方文件:
相关问题 更多 >
编程相关推荐