【发布时间】:2019-09-11 03:28:50
【问题描述】:
我有一个这样的字符串:
l1="[{'t_steps': '', 't_expected': '', 't_type': 'Functional', 't_precond': 'xxx', 't_notes': 'test note', 't_name': 'First test'}]"
我需要将它转换为一个真正的列表对象,例如:
l1=[{'t_steps': '', 't_expected': '', 't_type': 'Functional', 't_precond': 'xxx', 't_notes': 'test note', 't_name': 'First test'}]
我试过了:
l1=list(l1)
或
l1=l1.split(',')
但结果并不好。 请问有人可以帮我把我的字符串转换成python可以读取的形式吗?
提前非常感谢
【问题讨论】:
-
import ast; l1 = ast.literal_eval(string)
标签: python python-3.x list dictionary