configparser 配置文件模块
#_author:star
#date:2019/11/7
# configparser 配置文件模块
import configparser
config=configparser.ConfigParser()
# config['DEFAULT']={'ServerAliveInterval':'45',
# 'Compress':'yes',
# 'CompressionLevel':'9'}
# config['bitbucket.org']={'user':'hg'}
#
# config['topsecret.server.com']={}
# topsecret=config['topsecret.server.com']
# topsecret['Host Part'] ='50022'
#
# with open('example.ini','w') as configfile:
# config.write(configfile)
config.read('example.ini')
print(config.sections())#['bitbucket.org', 'topsecret.server.com'] 除了DEFAULT之外的其他内容
#查看DEFAULT
print(config.defaults())#OrderedDict([('serveraliveinterval', '45'), ('compress', 'yes'), ('compressionlevel', '9')])
print('bitbucket.org' in config)#True print(config['bitbucket.org']['user'])#hg for key in config:
print(key)
# DEFAULT
# bitbucket.org
# topsecret.server.com
print('----------------')
for key1 in config['bitbucket.org']:
print(key1)
# user
# serveraliveinterval
# compress
# compressionlevel
print('-------------')
config.remove_section('topsecret.server.com')#删除某一个块
print(config.has_section('topsecret.server.com'))#False
print(config.has_section('bitbucket.org'))#True config.set('DEFAULT','ServerAliveInterval','66') config.remove_option('DEFAULT','serveraliveinterval')#删除块下的某一个键值对
config.write(open('r.cfg','w'))#无论怎么修改文件,都要最后重写文件,因为文件一旦生成,就无法修改
Output:


configparser 配置文件模块的更多相关文章
- configparser配置文件模块
1.configparser的作用 mysql等很多文件的配置如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLeve ...
- hashlib摘要算法模块,logging日志,configparser配置文件模块
一.hashlib模块(摘要算法模块) 1.算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢? 摘要算法又称哈希算法.散列算法.它通过一个函数,把 ...
- configparser (配置文件) 模块
主要内容来自景女神博客 内涵:该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 常见文档格式: [DEFAULT] ...
- day31 configparser 配置文件模块
#__author__: Administrator #__date__: 2018/8/8 # configparse 生成配置文件,配置文会以件.ini结尾 # 对于格式有要求 # 创建配置文档 ...
- 面向对象总结、configparser配置文件模块、logging日志模块
面向对象总结 # 学习态度# python基础 2个月# html css js jq 1个月 # 上课困 # 学习方法 :# 列出知识点# 例子 写了哪些 # 面向对象学了哪些块# 为什么要讲面向对 ...
- Python之配置文件模块 ConfigParser
写项目肯定用的到配置文件,这次学习一下python中的配置文件模块 ConfigParser 安装就不说了,pip一下即可,直接来个实例 配置文件 project.conf [db] host = ' ...
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
时间模块 time datatime time.clock(2.7) time.process_time(3.3) 测量处理器运算时间,不包括sleep时间 time.altzone 返回与UTC时间 ...
- 第四十二节,configparser特定格式的ini配置文件模块
configparser用于处理特定格式的文件,其本质上是利用open来操作文件. 特定格式的ini配置文件模块,用于处理ini配置文件,注意:这个ini配置文件,只是ini文件名称的文本文件,不是后 ...
- Python模块之: ConfigParser 配置文件读取
Python模块之: ConfigParser 配置文件读取 ConfigParser用于读写类似INI文件的配置文件,配置文件的内容可组织为组,还支持多个选项值(option-value)类型. ...
随机推荐
- Java-Class-@I:org.springframework.beans.factory.annotation.Autowired
ylbtech-Java-Class-@I:org.springframework.beans.factory.annotation.Autowired 1.返回顶部 2.返回顶部 1. pack ...
- row_number() over(partition by a order by b desc) rn 用法
转载于:http://www.blogjava.net/kxbin/articles/360195.html 可以看看http://jingyan.baidu.com/article/9989c746 ...
- 《转》python对象
http://www.cnblogs.com/BeginMan/p/3160044.html 一.学习目录 1.pyhton对象 2.python类型 3.类型操作符与内建函数 4.类型工厂函数 5. ...
- QTP,自己主动化測试学习笔记,六月九号
測试自己主动化实现的两个难点设计--功能分解 实现--对象的识别 測试自己主动化实现的两个难点-功能分解 清晰画出业务流程图 依据业务流程分解业务功能.能够被复用的功能也要被分解出来. 依照路径覆盖的 ...
- 在线文库解决方案Jacob+SwfTools+FlexPaper
课程作业,准备做一个类似于豆丁之类的在线文库,解决方案也就是将文档(doc ppt xls)等转换成pdf,然后转成swf展示在页面中,今天下午经过研究,参考其他人的博客,实现了这个主要功能,这里也做 ...
- Eclipse指定JDK版本
Eclipse有好多版本,同时又分32位和64位,要使用相对应的版本和一样位数的JDK,Eclipse才能正常运行. 对应不上时,Eclipse 甚至不能正常启动.报错:“Failed to load ...
- 几个实用的js函数
在阅读JavaScript DOM编程艺术这本书时看到了一些比较实用的代码. //加载多个window.onload事件 function addLoadEvent(func) { var oldon ...
- redis随记
CONFIG REWRITE 将config文件 将服务器当前所使用的配置记录到 redis.conf 文件中.
- mysql主从同步的键值冲突问题的解决方法
转自https://njs375666635.iteye.com/blog/2242067 多主互备和主从复制有一些区别,因为多主中都可以对服务器有写权限,所以设计到自增长重复问题 出现的问题(多主自 ...
- Windows shutdown
用法: shutdown [/i | /l | /s | /sg | /r | /g | /a | /p | /h | /e | /o] [/hybrid] [/soft] [/fw] [/f] ...