python 操作ini配置文件的方法

1、首先安装常用的组件 : configobj模块

pip install configobj

 

2、然后引用即可

from configobj import ConfigObj
#注意大小写

 

3、使用举例

test.ini文件为如下关键词

[test_section]
test_param = test_value

 

那么python代码如下:

from configobj import ConfigObj  

config = ConfigObj("test.ini",encoding='UTF8')  

# 读配置文件  
print config['test_section']  
print config['test_section']['test_param '] 

 

posted @ 2021-12-02 22:03  正月龙  阅读(273)  评论(0编辑  收藏  举报
留言板