Python 配置文件的操作
来源:互联网 发布:淘宝上买到假货仅退款 编辑:程序博客网 时间:2024/06/09 20:32
读取配置文件的特定section和option
#!/usr/bin/python # -*- coding:UTF-8 -*-'''Created on 2015-4-30@author: huangpeng03'''import ConfigParser conf = ConfigParser.ConfigParser()conf.read('bsrom.cfg')host = conf.get('mysql', 'host')print host
写入特定section的option和value
#!/usr/bin/python # -*- coding:UTF-8 -*-'''Created on 2015-4-30@author: huangpeng03'''import ConfigParserconf = ConfigParser.ConfigParser()conf.add_section('newsection')conf.set('newsection', 'newoption', 'newvalue')f = open('bsrom.cfg','a+')conf.write(f)f.close()
修改
#!/usr/bin/python # -*- coding:UTF-8 -*-'''Created on 2015-4-30@author: huangpeng03'''import ConfigParserconf = ConfigParser.ConfigParser()conf.read('bsrom.cfg')conf.set('romkeyword', 'filepath', 'path2')f = open('bsrom.cfg','r+') #注意修改是r+模式conf.write(f)f.close()
#!/usr/bin/python # -*- coding:UTF-8 -*-'''Created on 2015-4-30@author: huangpeng03'''import ConfigParserconf = ConfigParser.ConfigParser()conf.read('bsrom.cfg')conf.remove_option('common', 'log_path') #删除配置项conf.remove_section('beanstalkc')f = open('bsrom.cfg','w+') #注意打开模式conf.write(f)f.close()
0 0
- Python 配置文件的操作
- python操作配置文件
- python操作conf配置文件
- Python 操作配置文件
- python配置文件操作
- python操作cfg配置文件
- python ConfigParser操作配置文件
- python 操作haproxy配置文件
- python操作配置文件
- python 3 ini配置文件操作
- 操作.net的配置文件
- 配置文件的读写操作
- 配置文件INI的操作
- Linux配置文件的操作
- python 的配置文件模块
- 关于Python的配置文件
- Python中利用ConfigParser操作配置文件
- python操作配置文件configparser 增删改查
- 微信开发(八)自动回复和多客服开发
- 可变参数
- MYSQL 的主主同步配置及问题
- Linux程序崩溃(segment fault)原因的调试
- intellij idea14 +tomcat7 ssh2 启动项目失败解决办法
- Python 配置文件的操作
- width、innerWidth、outerWidth(1)
- oracle中游标的使用
- 判断字符串是否为数字
- 解决通比牛牛dv,当全部玩家快速点开始按钮开始游戏时,玩家所发的牌有包括上局的牌,并且崩溃
- 嵌入式Linux字符设备驱动LED驱动编写
- iOS 沙盒(sandbox)机制和文件操作
- Android构建系统
- JfreeChart画图折线