【发布时间】:2011-12-25 10:14:52
【问题描述】:
我在将文件内容转换为字典列表时遇到问题,您能建议吗?
File content:
host1.example.com#192.168.0.1#web server
host2.example.com#192.168.0.5#dns server
host3.example.com#192.168.0.7#web server
host4.example.com#192.168.0.9#application server
host5.example.com#192.168.0.10#database server
文件夹中有多个格式相同的文件。最后,我想收到以下格式的字典列表:
[ {'dns': 'host1.example.com', 'ip': '192.168.0.1', 'description': 'web_server'},
{'dns': 'host2.example.com', 'ip': '192.168.0.5', 'description': 'dns server'},
{'dns': 'host3.example.com', 'ip': '192.168.0.7', 'description': 'web server'},
{'dns': 'host4.example.com', 'ip': '192.168.0.9', 'description': 'application server'},
{'dns': 'host5.example.com', 'ip': '192.168.0.10', 'description': 'database server'} ]
提前谢谢你!
【问题讨论】:
标签: python file list dictionary split