Python模块configparser(操作配置文件ini)
configparser模块提供对ini文件的增删改查方法。
ini文件的数据格式:
- [name1]
- attribute1=value1
- attribute2=value2
- [name2]
- attribute1=value1
- attribute2=value2
读取文件内容:
- import ConfigParser
- conf = ConfigParser.ConfigParser()
- conf.read('config.ini') # 文件路径
- a = conf.get("name1", "attribute1")
- print a
- b = conf.get("nmae2", "attribute2")
- print b
- 输出:
- value1
- value2
修改和增加内容:
- conf.set("name1","attribute1","") #修改attribute1的值或创建attribute1这个选项
- conf.add_section("name3") #增加name3部分
- conf.write(open('config.ini', 'w')) #写入操作
Python模块configparser(操作配置文件ini)的更多相关文章
- 记一次用python 的ConfigParser读取配置文件编码报错
记一次用python 的ConfigParser读取配置文件编码报错 ...... raise MissingSectionHeaderError(fpname, lineno, line)Confi ...
- python利用ConfigParser读写配置文件
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法非常简单. 配置文件的格式是: []包含的叫section, section 下有option=value这样的键值 ...
- Python模块 - configparser
configparser模块用来对配置文件进行操作 1.获取所有块 import configparser config = configparser.ConfigParser() config.re ...
- Python模块——configparser
configparser模块 该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值) 创建文件 import configp ...
- 保留注释换行的python模块configparser
python语言用来解析配置文件的模块是ConfigParser,python3中是configparser模块,我在使用中发现write方法在将配置项重新写入文 件时,配置文件中的空行和注释行都会被 ...
- Python利用ConfigParser读取配置文件
http://www.2cto.com/kf/201108/100384.html #!/usr/bin/python # -*- coding:utf-8 -*- import ConfigPars ...
- python模块(shelve,xml,configparser,hashlib,logging)
1.1shelve模块 shelve 模块比pickle模块简单,只有一个open函数,返回类似字典对象,可读可写:key必须为字符串, 而值可以是python所支持的数据类型. shelve模块主要 ...
- python 模块之-configparser
python 模块configparser 配置文件模块 import configparser config = configparser.ConfigParser() config[&q ...
- day20 二十、加密模块、操作配置文件、操作shell命令、xml模块
一.加密模块 1.hashlib模块:加密 ①有解密的加密方式 ②无解密的加密方式:碰撞检查 -- 1)不同数据加密后的结果一定不一致 -- 2)相同数据的加密结果一定是一致的 import hash ...
随机推荐
- angular路由详解五(辅助路由)
在HTML文件中 //主路由 <router-outlet></router-outlet> //辅助路由 <router-outlet name="aux& ...
- 2D变形transform的translate和rotate
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- MyBatis笔试题
1请写出Mybatis核心配置文件MyBatis-config.xml的内容? <?xml version="1.0" encoding="UTF-8"? ...
- react-native简单demo:实现加载豆瓣电影列表
https://github.com/axel10/react-native-douban' 相关随笔: react-native 开发环境搭建 http://www.cnblogs.com/axel ...
- Mininet简介
在Coursera SDN开放课程中,编程作业要用Mininet来完成.这里对Mininet做一个简单的介绍. 什么是Mininet Mininet是由一些虚拟的终端节点(end-hosts).交换机 ...
- mysql安装过程
1.到官网下载Mysql,目前最新版都是5.0以上版本,下载之后直接解压即可 2.在终端进入bin目录(如果嫌麻烦可配置环境变量,配置之后则无需进入bin目录则可敲命令),安装数据库服务:my ...
- wim命令删除后重新安装
个人原创博客,转载请注明,否则追究法律责任 2017-09-30-09:51:20 1,删除vim命令.模拟错误 [root@localhost ~]# which vim/usr/bin/vim[r ...
- 需求分析--WBS
我们的软件天气预报的WBS如下:
- 笔记:XML-解析文档-XPath 定位信息
如果需要定位某个XML文档中的一段特定信息,那么通过遍历DOM 树的众多节点来进行行查找显得有些麻烦,XPath语言使得访问树节点变得很容易,例如,下面的XML文档结构: <?xml versi ...
- redis客户端可以连接集群,但JedisCluster连接redis集群一直报Could not get a resource from the pool
一,问题描述: (如题目)通过jedis连接redis单机成功,使用JedisCluster连接redis集群一直报Could not get a resource from the pool 但是使 ...