【发布时间】:2011-08-22 00:31:05
【问题描述】:
假设我有一个包含以下内容的文本文件:
line = "this is line 1"
line2 = "this is the second line"
line3 = "here is another line"
line4 = "yet another line!"
我想快速将这些转换为字典键/值,其中“line*”作为键,引号中的文本作为值,同时删除等号。
在 Python 中执行此操作的最佳方法是什么?
【问题讨论】:
-
为什么要将它作为字典,而不是使用已经能理解这一点的众多配置文件解析器之一?
-
那些是哪些?
标签: python dictionary formatting key