python ini配置文件处理
2016-11-14 19:03
405 查看
一 ini 配置文件格式
节: [session]
参数: 键=值 name = value
例子: [port]
port1 = 8080
port2 = 6060
二 ConfigParser 库
节: [session]
参数: 键=值 name = value
例子: [port]
port1 = 8080
port2 = 6060
二 ConfigParser 库
>>> import configparser >>> cfg = configparser.ConfigParser() #创建对象 >>> cfg.read('test.ini') #读取ini配置文件 ['test.ini'] >>> cfg.sections() #读取所有节 ['Register', 'Version', 'General', 'AutoComp', 'Appearance', 'WindowStartup', 'AutoSave', 'QuickLaunch'] >>> cfg.items("Register") #读取某一节点参数 [('serial', '1336973314'), ('name', 'www.uzzf.com'), ('key', 'PCMDA-37G2V-G3V72-CADPM')] >>> cfg.set("Register","serial","abc") #修改参数(第一个参数为节点名称) >>> cfg.items("Register") [('serial', 'abc'), ('name', 'www.uzzf.com'), ('key', 'PCMDA-37G2V-G3V72-CADPM') ] >>> cfg.remove_option("Register", "serial") #删除节内参数 True >>> cfg.items("Register") [('name', 'www.uzzf.com'), ('key', 'PCMDA-37G2V-G3V72-CADPM')] >>> cfg.remove_section("Register") #删除节 True >>> cfg.sections() ['Version', 'General', 'AutoComp', 'Appearance', 'WindowStartup', 'AutoSave', 'QuickLaunch'] #使用write方法保存配置文件 >>> f = open('1.ini', 'w') >>> cfg.write(f) >>> f.close()
相关文章推荐
- python对ini配置文件处理
- 【脚本语言系列】关于Python结构化文本文件处理配置文件.ini,你需要知道的事
- [Python] 文件读写——处理ini配置文件
- python处理excel文档作为配置文件
- Python中INI配置文件的读取
- Python用ConfigParser解析INI配置文件
- Python中使用ConfigParser解析ini配置文件实例
- 通过python的ConfigParse模块读写ini配置文件
- Python读取ini配置文件
- python读写ini配置文件方法实例分析
- Python读取ini配置文件
- 标准C处理类似INI配置文件的键值型文档
- python 引用ini配置文件
- python 读取ini配置文件模块 configobj 介绍
- python 访问配置文件.ini
- 标准C处理类似INI配置文件的键值型文档
- python 读写 .ini 配置文件
- python 读写ini配置文件
- python 提供INI配置文件的操作 ConfigParser
- python开发_configparser_解析.ini配置文件工具_完整版_博主推荐