#_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 配置文件模块的更多相关文章

  1. configparser配置文件模块

    1.configparser的作用 mysql等很多文件的配置如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLeve ...

  2. hashlib摘要算法模块,logging日志,configparser配置文件模块

    一.hashlib模块(摘要算法模块) 1.算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢? 摘要算法又称哈希算法.散列算法.它通过一个函数,把 ...

  3. configparser (配置文件) 模块

    主要内容来自景女神博客 内涵:该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 常见文档格式: [DEFAULT] ...

  4. day31 configparser 配置文件模块

    #__author__: Administrator #__date__: 2018/8/8 # configparse 生成配置文件,配置文会以件.ini结尾 # 对于格式有要求 # 创建配置文档 ...

  5. 面向对象总结、configparser配置文件模块、logging日志模块

    面向对象总结 # 学习态度# python基础 2个月# html css js jq 1个月 # 上课困 # 学习方法 :# 列出知识点# 例子 写了哪些 # 面向对象学了哪些块# 为什么要讲面向对 ...

  6. Python之配置文件模块 ConfigParser

    写项目肯定用的到配置文件,这次学习一下python中的配置文件模块 ConfigParser 安装就不说了,pip一下即可,直接来个实例 配置文件 project.conf [db] host = ' ...

  7. 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时间 ...

  8. 第四十二节,configparser特定格式的ini配置文件模块

    configparser用于处理特定格式的文件,其本质上是利用open来操作文件. 特定格式的ini配置文件模块,用于处理ini配置文件,注意:这个ini配置文件,只是ini文件名称的文本文件,不是后 ...

  9. Python模块之: ConfigParser 配置文件读取

    Python模块之: ConfigParser 配置文件读取   ConfigParser用于读写类似INI文件的配置文件,配置文件的内容可组织为组,还支持多个选项值(option-value)类型. ...

随机推荐

  1. org.apache.jasper.JasperException: Unable to compile class for JSP: Invalid character constant

    这里不能用单引号,只能为双引号 request.setCharacterEncoding('gb2312');    String user = request.getParameter(" ...

  2. 大道浮屠诀---cwRsync同步工具的使用

    目的: 在日常生活中,我们有时候会遇到这样类似的问题 ---需要把一台服务器上的某个重要的文件进行备份(拷贝另外的服务器上) ---需要同步系统上的配置文件到其他系统 利用此cwRsync软件可以解决 ...

  3. HTML_CSS使用

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  4. JS事件 加载事件(onload)注意:1. 加载页面时,触发onload事件,事件写在<body>标签内。 2. 此节的加载页面,可理解为打开一个新页面时。

    加载事件(onload) 事件会在页面加载完成后,立即发生,同时执行被调用的程序. 注意:1. 加载页面时,触发onload事件,事件写在<body>标签内. 2. 此节的加载页面,可理解 ...

  5. ASP.NET打开项目错误:将指定的计数添加到该信号量中会导致其超过最大计数。

    1.错误如图 2.解决方案 重启IIS即可,运行-> 输入IISRESET 命令 即可重启IIS,如图

  6. mysql 复制原理详解

    http://www.cnblogs.com/kristain/articles/4142970.html

  7. MySQL数据库之DML(数据操作语言)

    对表记录的增删改 1.MySQL之DML创建数据表user create table user( id int unsigned not null auto_increment primary key ...

  8. c# 使用Expression 生成sql

    使用Expression 生成sql  update语句的时候遇到了个问题 ,Expression<Action<T>>  la   这个委托里面老获取不到 引用类型的值,甚至 ...

  9. CF822F Madness

    题意:给你一棵边权都为1的树,要求选择互不相交的若干条路径,这些路径包含有所有点. 在每一条路径上选择一条边,放置一个动点,设置一个方向,它开始在该路径上来回运动,速度为1.每个点上都有一个停表,当有 ...

  10. lock tables和unlock tables

    1.lock tables table1 read,table2 read,table3 read igoodful@a8-apple-iphone-db00.wh(glc) > show ta ...