#_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. RHEL / CentOS Linux Install Core Development Tools Automake, Gcc (C/C++), Perl, Python & Debuggers

    how do I install all developer tools such as GNU GCC C/C++ compilers, make and others, after install ...

  2. CometOJ Contest #3 C

    题目链接:https://cometoj.com/contest/38/problem/C?problem_id=1542&myself=0&result=0&page=1&a ...

  3. 安装mysql时,服务无法启动的问题

    1.下载mysql镜像文件:mysql-installer-community-8.0.17.0.msi 2.点击镜像进行安装,一直next即可 3.cmd以管理员身份,进入到安装的mysql安装目录 ...

  4. CentOS 7 下配置 Nginx + PHP7.1 + MariaDB 以及 Laravel 框架

    <!doctype html> CentOS 7 下配置 Nginx + PHP7.1 + MariaDB 以及 Laravel 框架.mdhtml {overflow-x: initia ...

  5. HDFS HA

  6. override和overload区别

    方法重载(overload)实现的是编译时的多态性(也称为前绑定) 方法重写(override)实现的是运行时的多态性(也称为后绑定)

  7. drupal7权限控制之-如何访问未发表的node

    在某些特殊需求的情况下,会涉及到匿名用户或非node节点所有者,访问未发表的node节点的需求:或者需要根据不同的用户角色,访问不同的内容类型等,如果不想安装node_access等模块的时候,可以在 ...

  8. day21 生成器,列表解析,三元表达式

    Python之路,Day9 = Python基础9 判断可迭代对象和迭代器 from collections import Iterable, Iterator # 导入模块功能,用来判断对象是否为I ...

  9. expect离线安装

    expect5.45.4.tar.gz和tcl8.4.11-src.tar.gz压缩包请前往以下链接下载: https://download.csdn.net/download/gangzi221/1 ...

  10. thinkphp 比较标签

    比较标签用于简单的变量比较,复杂的判断条件可以用if标签替换,比较标签是一组标签的集合,基本上用法都一致,如下: <比较标签 name="变量" value="值& ...