Python模块configparser(操作配置文件ini)
2018-02-02 14:20
811 查看
configparser模块提供对ini文件的增删改查方法。
ini文件的数据格式:
[name1] attribute1=value1 attribute2=value2 [name2] attribute1=value1 attribute2=value2
读取文件内容:
1 import ConfigParser 2 conf = ConfigParser.ConfigParser() 3 conf.read('config.ini') # 文件路径 4 a = conf.get("name1", "attribute1") 5 print a 6 b = conf.get("nmae2", "attribute2") 7 print b 8 9 10 输出: 11 value1 12 value2
修改和增加内容:
conf.set("name1","attribute1","666") #修改attribute1的值或创建attribute1这个选项 conf.add_section("name3") #增加name3部分 conf.write(open('config.ini', 'w')) #写入操作
相关文章推荐
- Python使用自带的ConfigParser模块读写ini配置文件
- Python使用自带的ConfigParser模块读写ini配置文件
- python模块之ConfigParser: 用python解析配置文件
- python中用Configparser模块解析配置文件
- Python自动化测试 -ConfigParser模块读写配置文件
- 使用python的ConfigParser模块方便的读取配置文件
- ConfigParser模块学习: 用python解析配置文件
- python模块之ConfigParser: 用python解析配置文件[zt]
- Python配置文件解析模块ConfigParser使用实例
- Python之配置文件模块 ConfigParser
- Python 中配置文件处理详解--ConfigParser,有了它就可随意操作配置文件了
- 【Python】配置文件解析模块ConfigParser使用实例
- 用ConfigParser模块读写配置文件——Python
- Python模块之ConfigParser - 读写配置文件
- Python用ConfigParser解析INI配置文件
- 第四十二节,configparser特定格式的ini配置文件模块
- python模块之ConfigParser: 用python解析配置文件
- Python模块之ConfigParser - 读写配置文件
- Python模块之ConfigParser - 读写配置文件
- [zz]python模块之ConfigParser: 用python解析配置文件