python读写配置文件
来源:互联网 发布:淘宝网iphone 7手机膜 编辑:程序博客网 时间:2024/05/21 10:54
本文主要介绍在python中读写配置文件。
一、python文件
python主要使用ConfigParser模块来进行配置文件的操作。
import ConfigParser#读操作conf = ConfigParser.ConfigParser()conf.read('config.ini') #文件名#读取指定的section和name项user = conf.get('global', 'user')password = conf.get('global', 'password')#获取所有的sectionsections = conf.sections()----------#写操作# 更新指定section, option的值conf.set("section2", "port", "8081")# 写入指定section, 增加新option的值conf.set("section2", "IEPort", "80")# 添加新的 sectionconf.add_section("new_section")conf.set("new_section", "new_option", "http://www.cnblogs.com/tankxiao")# 写回配置文件conf.write(open("c:\\test.conf","w"))
二、配置文件
config.ini配置文件内容如下:
[global]user = 'root'password = 'test'
阅读全文
0 0
- python 读写 .ini 配置文件
- python 读写ini配置文件
- python读写配置文件
- python读写配置文件
- python读写csv_xml_json配置文件
- python读写配置文件
- Python读写配置文件
- 【python】ConfigParser---读写配置文件
- 【python】configparser读写配置文件
- python读写配置文件
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- 规范Python程序配置文件读写
- python-ConfigParser模块【读写配置文件】
- ConfigReader(五十五)—— ReadSkillMoveConfig
- PHP 如何在Redis中实现事物(事物提交和事物回滚)
- 数据库设计三大范式
- 剑指offer--变态跳台阶
- shadowsocksr 快速搭建
- python读写配置文件
- C语言基础练习4
- 并发编程(二)-访问共享资源
- 运维常用网址大全
- Intellij IDEA database配置 [全局配置][mysql]
- libc.so.6: cannot open shared object file报错处理
- 内存篇之指向栈的指针
- 单用户模式+救援模式找回root密码
- 海云安带你解读移动金融APP安全报告