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. DEVOPS技术实践_20:串联多个job执行

    在jenkins可能会有战役中场景,就是在一个job执行完之后,把这个执行结果作为另一个job的执行条件 比如A执行完,如果A执行成功,则执行B,如果失败则执行C 1 前期准备 A任务 import ...

  2. Mac常用的软件推荐

    Alfred 效率软件,让能更快的启动各种软件 VScode 编辑器,市面上最热的编辑器,好用的不只是一点点,加上Vim插件简直就是秒杀市面上各种IDE PicGo 一个开源图床软件,支持各大网站的图 ...

  3. C#反射与特性(二):探究反射

    目录 1,反射的使用概述 2,获取 Type 在上一章中,我们探究了 C# 引入程序集的各种方法,这一章节笔者将探究 C# 中使用反射的各种操作和代码实践. 1,反射的使用概述 1.1 什么是反射 & ...

  4. 洛谷P1220 关路灯 题解 区间DP

    题目链接:https://www.luogu.com.cn/problem/P1220 本题涉及算法:区间DP. 我们一开始要做一些初始化操作,令: \(p[i]\) 表示第i个路灯的位置: \(w[ ...

  5. 「学习笔记」珂朵莉树 ODT

    珂朵莉树,也叫ODT(Old Driver Tree 老司机树) 从前有一天,珂朵莉出现了... 然后有一天,珂朵莉树出现了... 看看图片的地址 Codeforces可还行) 没错,珂朵莉树来自Co ...

  6. Python基础复习函数篇

    目录 1.猴子补丁2. global和nonlocal关键字3.迭代器和生成器4.递归函数5.高阶函数和lamdba函数6.闭包7.装饰器 1.   猴子补丁 猴子补丁主要用于在不修改已有代码情况下修 ...

  7. 曹工说Spring Boot源码(8)-- Spring解析xml文件,到底从中得到了什么(util命名空间)

    写在前面的话 相关背景及资源: 曹工说Spring Boot源码(1)-- Bean Definition到底是什么,附spring思维导图分享 曹工说Spring Boot源码(2)-- Bean ...

  8. SpringBoot2 整合 Zookeeper组件,管理架构中服务协调

    本文源码:GitHub·点这里 || GitEE·点这里 一.Zookeeper基础简介 1.概念简介 Zookeeper是一个Apache开源的分布式的应用,为系统架构提供协调服务.从设计模式角度来 ...

  9. Netty快速入门(03)Java NIO 介绍-Buffer

    NIO 介绍 NIO,可以说是New IO,也可以说是non-blocking IO,具体怎么解释都可以. NIO 1是在JSR51里面定义的,在JDK1.4中引入,因为BolckingIO不支持高并 ...

  10. css写斜角

    项目开发中遇到了这样的效果,百度了一波,可以使用css3的伪类实现: /*斜角公用*/1.外层的div加class='wrapper' 并需要设置相对定位 .wrapper:before { -moz ...