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 '] 
原文地址:https://www.cnblogs.com/webcyz/p/15635625.html