import configparser #配置文件

config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '45',
'Compression': 'yes',
'CompressionLevel': '9'} config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = '50022' # mutates the parser
topsecret['ForwardX11'] = 'no' # same here
with open('example.ini', 'w') as configfile:
config.write(configfile)
config.read('example.ini')#用于调用对象
print(config.sections())
print('bytebong.com' in config)#判断
print(config['bitbucket.org']['User'])
print(config['DEFAULT']['Compression']) for key in config['bitbucket.org']:
print(key) print(config.options('bitbucket.org'))#取出键对应的值 【DEFAULT】是默认的 里面的值也会被取出来
print(config.items('bitbucket.org'))#取出键值对 【DEFAULT】是默认的 里面的键值也会被取出来
print(config.get('bitbucket.org','compression'))
config.remove_section('topsecret.server.com')#删除键
config.remove_option('bitbucket.org','user')#删除值
config.set('bitbucket.org','user','11111') #更改键对应的值 config.write(open('example.ini', "w")) #增删改并不是在原文件上修改而是重新覆盖或生成
import configparser #配置文件

config = configparser.ConfigParser()
# config["DEFAULT"] = {'ServerAliveInterval': '45',
# 'Compression': 'yes',
# 'CompressionLevel': '9'}
#
# config['bitbucket.org'] = {}
# config['bitbucket.org']['User'] = 'hg'
# config['topsecret.server.com'] = {}
# topsecret = config['topsecret.server.com']
# topsecret['Host Port'] = '50022' # mutates the parser
# topsecret['ForwardX11'] = 'no' # same here
# with open('example.ini', 'w') as configfile:
# config.write(configfile)
config.read('example.ini')#用于调用对象
# print(config.sections())
# print('bytebong.com' in config)#判断
# print(config['bitbucket.org']['User'])
# print(config['DEFAULT']['Compression'])
#
#
# for key in config['bitbucket.org']:
# print(key)
#
# print(config.options('bitbucket.org'))#取出键对应的值 【DEFAULT】是默认的 里面的值也会被取出来
# print(config.items('bitbucket.org'))#取出键值对 【DEFAULT】是默认的 里面的键值也会被取出来
# print(config.get('bitbucket.org','compression'))
# config.remove_section('topsecret.server.com')#删除键
# config.remove_option('bitbucket.org','user')#删除值
# config.set('bitbucket.org','user','11111') #更改键对应的值
#
# config.write(open('example.ini', "w")) #增删改并不是在原文件上修改而是重新覆盖或生成

config 模块的更多相关文章

  1. SpringCloud创建Config模块

    1.说明 本文详细介绍Spring Cloud创建Config模块的方法, 基于已经创建好的Spring Cloud父工程, 请参考SpringCloud创建项目父工程, 创建Config模块这个子工 ...

  2. logging.config模块---使用配置文件管理logger

    logging配置文件 一.使用到的模块: logging.config 官方文档: https://docs.python.org/3/library/logging.config.html 非官方 ...

  3. Py-re正则模块,log模块,config模块,哈希加密

    9.re正则表达式模块,用于字符串的模糊匹配 元字符: 第一:点为通配符 用.表示匹配除了换行符以外的所有字符 import re res=re.findall('a..x','adsxwassxdd ...

  4. drupal7为admin/config页面添加自己开发的模块

    1.实现显示模块 //admin/config配置页面添加journal块 $items['admin/config/journal'] = array(//注意格式为'admin/config/模块 ...

  5. python学习笔记之常用模块(第五天)

    参考老师的博客: 金角:http://www.cnblogs.com/alex3714/articles/5161349.html 银角:http://www.cnblogs.com/wupeiqi/ ...

  6. 谈谈.net模块依赖关系及程序结构

    技术为解决问题而生. 上面这个命题并非本文重点,我将来有空再谈这个.本文也并非什么了不起的技术创新,只是分享一下我对.net模块依赖关系及程序结构方面的一些看法.先看一个最最简单的hello worl ...

  7. python日志模块---logging

    1.将日志打印到屏幕 import logging logging.debug('This is debug message---by liu-ke') logging.info('This is i ...

  8. Python中的日志管理Logging模块

    1.基本的用法 import logging logging.debug('This is debug message') logging.info('This is info message') l ...

  9. Python(2.7.6) 标准日志模块 - Logging Configuration

    除了使用 logging 模块中的 basicConfig 方法配置日志, Python 的 logging.config 模块中, dictConfig 和 fileConfig 方法分别支持通过字 ...

随机推荐

  1. 利用docker容器运行.net core webapi

    利用docker容器运行.net core webapi :first-child { margin-top: 0 !important; } > :last-child { margin-bo ...

  2. jeecg中自定义按钮时遇到的问题

  3. Appium Mac系统 自动测试环境搭建

    一.python 环境准备 Mac 自带 Python 环境,一般为 2.7 版本. 1.查看当前系统默认的Python路径 which python ==> /usr/bin/python 2 ...

  4. SpringBoot-2.1.1系列二:使用websocket

    1.什么是websocket? WebSocket协议是基于TCP的一种新的网络协议.它实现了浏览器与服务器全双工(full-duplex)通信--允许服务器主动发送信息给客户端. 2.为什么需要使用 ...

  5. git命令的基本使用流程

    git命令的基本使用流程 前提:已经基本熟悉git的常用命令 1.提交项目 首先,在对项目进行完善后,如果想要将项目更新到github或是阿里code上去,先要使用 git add -A 这一命令的作 ...

  6. C语言---总结

    基础 程序结构是三种: 顺序结构.选择结构(分支结构).循环结构. 读程序都要从 main()入口, 然后从最上面顺序往下读(碰到循环做循环,碰到选择做选择),有且只有一个main函数. 计算机的数据 ...

  7. C#反射与特性(五):类型成员操作

    目录 1,MemberInfo 1.1 练习-获取类型的成员以及输出信息 1.2 MemberType 枚举 1.3 MemberInfo 获取成员方法并且调用 1.4 获取继承中方法的信息(Decl ...

  8. C#反射与特性(七):自定义特性以及应用

    目录 1,属性字段的赋值和读值 2,自定义特性和特性查找 2.1 特性规范和自定义特性 2.2 检索特性 3,设计一个数据验证工具 3.1 定义抽象验证特性类 3.2 实现多个自定义验证特性 3.3 ...

  9. [Debug]IOS微信浏览器不支持form表单的target=_blank

    测试代码如下 <?php echo '<meta name="viewport" content="width=device-width,minimum-sc ...

  10. python 多进程处理图像,充分利用CPU

    默认情况下,Python程序使用一个CPU以单个进程运行.不过如果你是在最近几年配置的电脑,通常都是四核处理器,也就是有8个CPU.这就意味着在你苦苦等待Python脚本完成数据处理工作时,你的电脑其 ...