#_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. Devstack单节点环境实战配置

    本文为minxihou的翻译文章,转载请注明出处Bob Hou: http://blog.csdn.net/minxihou JmilkFan:minxihou的技术博文方向是 算法&Open ...

  2. ps-使用通道抠图为XX换背景

    第一步先载入图片 点击通道,复制蓝色通道 然后点击新的蓝色通道,图像-调整-曲线-改变输入输出, 然后用历史画笔全部填黑.  然后载入选区,复制.在图层中新建蒙版 黏贴,反向(CTRL+I)就可以了. ...

  3. springboot + ajax + mybatis 实现批量删除

    实现思路: 1. checkbox全选获取批量删除的id数组 2. ajax以字符串的形式将id数组传给控制器 3. 控制器将字符串分割成List数组作为参数传给mapper 具体代码: 1. 前端代 ...

  4. websokect的原理

    WebSocket 机制 以下简要介绍一下WebSocket的原理及运行机制. WebSocket是HTML5下一种新的协议.它实现了浏览器与服务器全双工通信,能更好的节省服务器资源和带宽并达到实时通 ...

  5. Ubuntu18.04 安装搜狗拼音

    参考文章:https://blog.csdn.net/fx_yzjy101/article/details/80243710 1. 安装fcitx sudo apt-get install fcitx ...

  6. EXCEL表格链接SQLSEVER数据库

    Sub 数据库连接()     Set Cnn = CreateObject("ADODB.Connection")    Set rs = CreateObject(" ...

  7. ubuntu 权限不够,解决办法,无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)

    终端执行  sudo passwd root输入root 新密码执行命令  nano /usr/share/lightdm/lightdm.conf.d/50-ubuntu.conf末行添加   gr ...

  8. H5点击拨打电话,发短信

    phone(){ window.location.href = 'tel:123123'// 拨打电话 window.location.href = 'sms:123123'// 发短信 }

  9. 廖雪峰Java16函数式编程-2Stream-4map

    1. map()简介 Stream.map()是一个Stream的转换方法,把一个stream转换为另一个Stream,这2个Stream是按照映射函数一一对应的. 所谓map操作,就是把一种操作运算 ...

  10. SQL Server ODBC 解决方案

    { } { }