• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > Python自动化测试ConfigParser模块读写配置文件

Python自动化测试ConfigParser模块读写配置文件

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python configparser,python中configparser,python3 configparser,configparser模块,configparser等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Python自动化测试ConfigParser模块读写配置文件

ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单。 直接上代码,不解释,不多说。

配置文件的格式是: []包含的叫section,    section 下有option=value这样的键值

配置文件   test.conf   

[section1]
name = tank
age = 28

[section2]
ip = 192.168.1.1
port = 8080
</div>

Python代码

# -* - coding: UTF-8 -* - 
import ConfigParser

conf = ConfigParser.ConfigParser()
conf.read("c:\\test.conf")

# 获取指定的section, 指定的option的值
name = conf.get("section1", "name")
print(name)
age = conf.get("section1", "age")
print age

#获取所有的section
sections = conf.sections()
print sections

#写配置文件

# 更新指定section, option的值
conf.set("section2", "port", "8081")

# 写入指定section, 增加新option的值
conf.set("section2", "IEPort", "80")

# 添加新的 section
conf.add_section("new_section")
conf.set("new_section", "new_option", "http://www.cnblogs.com/tankxiao")

# 写回配置文件
conf.write(open("c:\\test.conf","w"))
</div>

以上就是对Python ConfigParser模块读写配置文件的资料整理,后续继续补充相关资料,谢谢大家对本站的支持!

</div>

您可能想查找下面的文章:

  • Python自动化测试ConfigParser模块读写配置文件
  • Python自动化测试ConfigParser模块读写配置文件
  • Python使用自带的ConfigParser模块读写ini配置文件
  • Python中的ConfigParser模块使用详解
  • Python中的ConfigParser模块使用详解
  • Python中使用ConfigParser解析ini配置文件实例
  • Python中使用ConfigParser解析ini配置文件实例
  • python解析模块(ConfigParser)使用方法
  • python解析模块(ConfigParser)使用方法

相关文章

  • 在Mac OS上部署Nginx和FastCGI以及Flask框架的教程
  • Python 除法小技巧
  • 使用Python抓取模板之家的CSS模板
  • 详解python并发获取snmp信息及性能测试
  • Python显示进度条的方法
  • Python实现把xml或xsl转换为html格式
  • 使用Python读写及压缩和解压缩文件的示例
  • python提取字典key列表的方法
  • 爬山算法简介和Python实现实例
  • Django框架下在URLconf中指定视图缓存的方法

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python使用smtplib模块发送电子邮件的流程详解
    • Python底层封装实现方法详解
    • 初步认识Python中的列表与位运算符
    • Windows下PyMongo下载及安装教程
    • Python实现HTTP协议下的文件下载方法总结
    • Python的Urllib库的基本使用教程
    • python通过apply使用元祖和列表调用函数实例
    • Python线程指南详细介绍
    • 详解python并发获取snmp信息及性能测试
    • 跟老齐学Python之关于类的初步认识

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有