• 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)使用方法

相关文章

  • python利用hook技术破解https的实例代码
  • Eclipse和PyDev搭建完美Python开发环境教程(Windows篇)
  • python实现的AES双向对称加密解密与用法分析
  • pygame播放音乐的方法
  • python读写二进制文件的方法
  • Python中暂存上传图片的方法
  • 简述Python中的面向对象编程的概念
  • Python实现将数据库一键导出为Excel表格的实例
  • Python读取mp3中ID3信息的方法
  • 使用Python的Tornado框架实现一个Web端图书展示页面

文章分类

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

最近更新的内容

    • python实现问号表达式(?)的方法
    • Python中的map()函数和reduce()函数的用法
    • python实现文本去重且不打乱原本顺序
    • Django日志模块logging的配置详解
    • 编写Python小程序来统计测试脚本的关键字
    • Python生成随机MAC地址
    • python共享引用(多个变量引用)示例代码
    • 浅析Python中元祖、列表和字典的区别
    • Python中的自定义函数学习笔记
    • Python求算数平方根和约数的方法汇总

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

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