【发布时间】:2019-01-13 04:22:37
【问题描述】:
我正在尝试从文本文件中获取存储在列表中的字典
我搜索了一个json函数,它可以将字符串分隔并保存在一个列表(字典列表)中,但不知道有没有这样的东西。
txt:
[{"Principal": ["Jhon","Anderson","40"]}, {"Secretary": ["Marie","Garcia","29"]},{"Councilor": ["Alan", "Smith","33"]}]
py 代码:
stringvar=textfile.read()
//for 或下面的函数
dictionaries=json.loads(textfile.read())
otherlist=dictionaries
【问题讨论】:
-
我想我是具体的,txt文件看起来就像它在一行中,我想要实现的是将它保存在几个字典中,稍后我会放在一个列表中,谢谢跨度>
-
dictionaries=json.loads(textfile.read())已经是一个字典列表。你想念什么?
标签: python list dictionary text-files