python - 从 Python(2.7) 中的配置文件中读取该部分作为字典
问题描述
我有一个包含以下部分的配置文件
[TEST]
fruit=["apple","select * from apple"]
vegetable=["carrot","select * from carrot"]
我正在尝试使用以下代码将该部分加载到 python 字典中
config=ConfigParser.RawConfigParser()
config.optionxform =str
cofigPath='/home/ini/target.ini'
config.read(configPath)
现在,当我试图将该部分加载到字典中时,我没有在值中获取列表,而是将其存储为字符串
tabList=dict(config.items('TEST'))
for k, v in tableList.iteritems():
print(k,v[0])
v[0] 没有打印 "apple" ,而是将字典的值部分作为字符串并将 v[0] 打印为 "[" ,即字典值的第一个字符。
请建议我应该合并什么以将该部分读入字典,当我遍历字典时我可以将列表作为值
解决方案
推荐阅读
- regex - 带有可选结束字符的 PCRE2 正则表达式始终匹配可选结束字符
- python - API Router Depends 与 Depend() 不兼容
- java - Jhipster 使用 Websocket 和 Vue 构建,不进行身份验证或登录
- php - 如何区分 Octobercms 后端表单中的关系
- postgresql - 如何在 Postgresql 的选择中重新映射数组列值?
- scala - 根据spark scala中完整df的列值设置列值
- vue.js - 当vue router-link完成导航时如何运行回调
- xml - 什么 .NET 类和方法可用于替换 XML 中的单引号和双引号以及其他特殊字符?
- python - 如何使用 tkinter 制作带有框架的标签?
- tensorflow - TensorFlow Object Detection API 量化,输出张量为 TFLite_Detection_PostProcess