config 模块
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 模块的更多相关文章
- SpringCloud创建Config模块
1.说明 本文详细介绍Spring Cloud创建Config模块的方法, 基于已经创建好的Spring Cloud父工程, 请参考SpringCloud创建项目父工程, 创建Config模块这个子工 ...
- logging.config模块---使用配置文件管理logger
logging配置文件 一.使用到的模块: logging.config 官方文档: https://docs.python.org/3/library/logging.config.html 非官方 ...
- Py-re正则模块,log模块,config模块,哈希加密
9.re正则表达式模块,用于字符串的模糊匹配 元字符: 第一:点为通配符 用.表示匹配除了换行符以外的所有字符 import re res=re.findall('a..x','adsxwassxdd ...
- drupal7为admin/config页面添加自己开发的模块
1.实现显示模块 //admin/config配置页面添加journal块 $items['admin/config/journal'] = array(//注意格式为'admin/config/模块 ...
- python学习笔记之常用模块(第五天)
参考老师的博客: 金角:http://www.cnblogs.com/alex3714/articles/5161349.html 银角:http://www.cnblogs.com/wupeiqi/ ...
- 谈谈.net模块依赖关系及程序结构
技术为解决问题而生. 上面这个命题并非本文重点,我将来有空再谈这个.本文也并非什么了不起的技术创新,只是分享一下我对.net模块依赖关系及程序结构方面的一些看法.先看一个最最简单的hello worl ...
- python日志模块---logging
1.将日志打印到屏幕 import logging logging.debug('This is debug message---by liu-ke') logging.info('This is i ...
- Python中的日志管理Logging模块
1.基本的用法 import logging logging.debug('This is debug message') logging.info('This is info message') l ...
- Python(2.7.6) 标准日志模块 - Logging Configuration
除了使用 logging 模块中的 basicConfig 方法配置日志, Python 的 logging.config 模块中, dictConfig 和 fileConfig 方法分别支持通过字 ...
随机推荐
- java基础 -- 关键字final的用法
用法一(修饰变量): Final变量能被显式地初始化并且只能初始化一次.被声明为final的对象的引用不能指向不同的对象.但是final对象里的数据可以被改变.也就是说final对象的引用不能改变,但 ...
- 浅谈Redis的基本原理和数据类型结构的特性和应用开发场景
一.Redis介绍 1,redis介绍(Redis安装在磁盘:Redis数据存储在内存) redis是一种基于键值对(key-value)数据库,其中value可以为string.hash.list. ...
- 洛谷$1220$ 关路灯 记搜/$DP$
\(Sol\) 约定\(pos\)为老张所处的位置的路灯号,\(i<pos,j>pos\). 显然,如果\(i\)和\(j\)都关了,那么它们之间的所有灯一定也都关了. 设\(f[i][j ...
- 「Luogu P2015」二叉苹果树 解题报告
题面 一个二叉树,边数为n\((2<n\le 100)\),每条边有一个权值,求剪枝后剩下p\((1<p<n)\)条边,使p条边的权值和最大 还看不懂?-- 2 5 input:5 ...
- (三)unittest断言方法的介绍
断言如同在测试用例上,类似于预期结果与实际结果是否一致,如果一致则表示测试通过,Assert断言很好的用于测试结果判断上,更灵活的对预期结果和实际结果进行对比,下面简单的介绍一下unittest的As ...
- 【原】C#两个类互相包含类对象可以吗?
在阅读大牛代码的时候发现了这个问题,之所以标题以问号开头,是因为我还没搞懂这个问题.权当记录,以希望以后搞懂. 部分图片转贴吧:http://tieba.baidu.com/p/6015910029 ...
- Netty--【详解】
Netty概述:1.netty是基于Java NIO的网络应用框架,client-server框架2.Netty是一个高性能.异步事件驱动的NIO框架,它提供了对TCP.UDP和文件传输的支持,作为一 ...
- python之嵌套函数调用
#定义嵌套函数 def func1(): print('this is func1') def func2(): print('this is func2')#调用1func1()输出:this is ...
- 集合下篇—Map和Set 源码分析
Map Map不同于Collection集合,Map存放的是键值对,且键不能重复 1 .HashMap (底层是哈希表,Java中用链表的数组实现,存取顺序不一致) 这篇博客主要讲集合的,哈希表这样的 ...
- 一文读懂MapReduce 附流量解析实例
1.MapReduce是什么 Hadoop MapReduce是一个软件框架,基于该框架能够容易地编写应用程序,这些应用程序能够运行在由上千个商用机器组成的大集群上,并以一种可靠的,具有容错能力的方式 ...