修改配置文件configparser
2018-01-15 23:05
148 查看
import configparser start = configparser.ConfigParser() start.read("config.ini") section = start.section() print(section) options = start.options('mysqld') print('options') options1 = start.options('count') items = start.items('mysqld') items1 = start.items('count') print (items) print (items1) host = start.get("mysqld","host") port = start.get("mysqld","port") user = start.get("mysqld","user") password = start.get("mysqld","password") print(host) print(port) print(user) print(password) ''' start.add_section("add") 添加[add] start.write(open("config.ini","w")) 写入到配置文件里 ''' if start.has_section("add"): print("already add") else: print("not add ") start.add_section("add") start.set("add","name","test") start.write(open("config.int","w")) if start.has_section("del"): print("already del") else: print("not del ") start.remove_section("del") print(delete success) start.write(open("config.int","w")) ''' start.remove_option("count","count_num") 删除[count]的count_num类数据 start.write(open("config.int","w")) 写入到配置文件 ''' if start.del_option("count","count_num"): print("if count_num,new delete") start.remove_option("count","count_num") start.write(open("config.ini","w")) print("delete count_num") else: print("not count_num") ''' start.set("count","count_num","22") start.write(open("config.int","w")) ''' if start.new_section("count","count_num","2"): start.set("count","count_num","22") start.write(open("config.ini","w")) else: print("error")
相关文章推荐
- Python configparser修改配置文件
- ConfigParser读取记事本、notepad++修改后的配置文件会出现:ConfigParser.MissingSectionHeaderError
- Python自动化测试 (二) ConfigParser模块读写配置文件
- 读写配置文件ConfigParser
- 通过代码修改config文件中的配置
- python读取配置文件configparser
- 第四十二节,configparser特定格式的ini配置文件模块
- 修改eclipse config文件配置
- ueditor上传图片时目录创建失败的问题解决方法,不用那么麻烦,其实修改php/config.json这个配置文件里面的路径就行!!
- python3 configparser对配置文件读写
- WinForm修改App.config配置文件功能
- JM代码修改默认配置文件.config
- Python使用自带的ConfigParser模块读写ini配置文件
- configparser模块读写ini配置文件
- python中读取配置文件ConfigParser
- python ConfigParser – 配置文件解析(转载)
- [置顶] c# asp.net 修改webconfig文件 配置
- Python自动化测试 -ConfigParser模块读写配置文件
- 【Python】配置文件解析模块ConfigParser使用实例
- Asp.Net2.0新增/修改/删除 配置文件(*.config)节点