【发布时间】:2015-04-29 22:07:46
【问题描述】:
我创建了一个文件并且有一个字典。 现在我想要文件中的那个字典,但我不想要字符串,也不想要换行符。 我得到了这样的东西:
"{'Greennhouse 1': {'Product': '4', 'Location of greenhouse': '2',
'Unities of the product': 6, 'Designation': '1', 'Growth state of the
product': '5', 'Code of wsn': 1, 'Area of greenhouse': 3}}\n"
但我想要这个:
{'Greennhouse 1': {'Product': '4', 'Location of greenhouse': '2',
'Unities of the product': 6, 'Designation': '1', 'Growth state of the
product': '5', 'Code of wsn': 1, 'Area of greenhouse': 3}}
【问题讨论】:
-
你尝试了什么?您的文件看起来如何?
-
我尝试使用 dict,我在这里看到了一些东西,但它不起作用,因为我猜我在另一部字典中有一本字典。我想创建一个新字典并将元素放在那里,但我现在不知道如何获取 str...
-
鉴于问题中的描述,
ast.literal_eval显然是要走的路。 -
@SaicharanSM 我实际上已经看到了,但我想避免任何其他进口(因为我已经有很多)。
标签: python string dictionary newline