Python自动化测试 (二) ConfigParser模块读写配置文件
来源:互联网 发布:mac 终端更改时间date 编辑:程序博客网 时间:2024/05/16 05:29
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单。 直接上代码,不解释,不多说。
配置文件的格式是: []包含的叫section, section 下有option=value这样的键值
配置文件 test.conf
[section1]name = tankage = 28[section2]ip = 192.168.1.1port = 8080
Python代码
# -* - coding: UTF-8 -* - import ConfigParserconf = ConfigParser.ConfigParser()conf.read("c:\\test.conf")# 获取指定的section, 指定的option的值name = conf.get("section1", "name")print(name)age = conf.get("section1", "age")print age#获取所有的sectionsections = conf.sections()print 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"))
0 0
- Python自动化测试 (二) ConfigParser模块读写配置文件
- Python自动化测试 (二) ConfigParser模块读写配置文件
- Python自动化测试 ConfigParser模块读写配置文件
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- python-ConfigParser模块【读写配置文件】
- Python - ConfigParser模块读写配置文件
- 【python】ConfigParser---读写配置文件
- 【python】configparser读写配置文件
- PYTHON 配置文件模块 ConfigParser
- Python 配置文件 ConfigParser 模块
- 用python做自动化测试--logging 和ConfigParser 模块
- 【ConfigParser模块】Python处理配置文件
- Python之配置文件模块 ConfigParser
- windows系统下javac使用utf8编码
- Delphi中如何让编辑框只能输入数字或者只能输入一个浮点数值呢?
- 处理芯片cel格式数据的全自动R代码
- my_print_defaults: command not found
- Qt实现屏保功能,鼠标一定时间无响应程序进入待机状态
- Python自动化测试 (二) ConfigParser模块读写配置文件
- 黑马程序员------------------继承
- 图的表示--邻接矩阵
- T检验、F检验
- BRISK:Binary Invariant Scalable Keypoint——配置与运行
- 开源SSL加快器的构建
- 【Codility】Dominator ★★
- 新人入职拿到一个新的框架,如何去做?
- Oracle EBS - Forms Servlet与Socket模式比较