python模块--config
一、创建文件
##-----------------创建数据表--------------------------
import configparser
config = configparser.ConfigParser() config["DEFAULT"] = {
'ServerAliveInterval': '',
'Compression': 'yes',
'CompressionLevel': ''
} config["bitbucket.org"] = {}
config["bitbucket.org"]["user"] = "hg" config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com'] # ?
topsecret['Host Post'] = '' #mutates the parser
topsecret['ForwardX11'] = 'no' #same here with open('example.ini','w') as f:
config.write(f)
2、增删改查--查
###----------增删改查------------------------------
import configparser
config = configparser.ConfigParser() print(config.sections()) # 返回空列表[]
# print(config.user())
##------------> 查
config.read('example.ini')
print(config.sections()) #['bitbucket', 'topsecret.server.com'] print('bytebong.com' in config) #False
print(config['bitbucket.org']['user']) # hg print(config['topsecret.server.com']['host post']) #
print(config['topsecret.server.com']['forwardx11']) #no
print(config['DEFAULT']['serveraliveinterval']) # for key in config['bitbucket.org']:
print('【bit】',key) print(config.options('bitbucket.org')) # ??['user', 'serveraliveinterval', 'compression', 'compressionlevel']
print(config.items('bitbucket.org')) #[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9'), ('user', 'hg')]
## 下面的两组,不管取哪个,都会把[DEFAULT] 里面的顺带打印出来,这以后在实际中有相应的应用、 print(config.get('bitbucket.org','compression')) #?? yes
3、增、改、删
##------> 删、改、增
config.add_section('zhao') # 增加一条
config.set('zhao','key','python') config.remove_section('topsecret.server.com')
config.remove_option('bitbucket.org','user') config.write(open('zhao',"w"))
python模块--config的更多相关文章
- Python模块之configpraser
Python模块之configpraser 一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...
- python 学习第五天,python模块
一,Python的模块导入 1,在写python的模块导入之前,先来讲一些Python中的概念性的问题 (1)模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质是.py ...
- python模块介绍- multi-mechanize 性能测试工具
python模块介绍- multi-mechanize 性能测试工具 2013-09-13 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq 3739 ...
- python模块:网络协议和支持
python模块:网络协议和支持 webbrowser 调用浏览器显示html文件 webbrowser.open('map.html') [webbrowser - Convenient Web-b ...
- python模块部分----模块、包、常用模块
0.来源:https://www.cnblogs.com/jin-xin/articles/9987155.html 1.导入模块 1.1模块就是一个python文件,模块名是文件名 1.2导入模块的 ...
- python模块之_正则 re_configparser_logging_hashlib
正则表达式的内容放在最下面了 configparser 模块: #!/usr/bin/env python # coding:utf-8 import configparser # 专门用于操作配置文 ...
- 【转】python模块分析之logging日志(四)
[转]python模块分析之logging日志(四) python的logging模块是用来写日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分 ...
- python 模块之-configparser
python 模块configparser 配置文件模块 import configparser config = configparser.ConfigParser() config[&q ...
- python 模块之-logging
python 模块logging import logging ### 简单使用格式 日志级别等级CRITICAL > ERROR > WARNING > INFO > ...
随机推荐
- CSP(Content Security Policy) 入门教程
参考: http://www.ruanyifeng.com/blog/2016/09/csp.html https://developer.mozilla.org/en-US/docs/Web/HTT ...
- ctci1.3
; i < len; i++){ if(str0[i] != str1[i]) return false; } return t ...
- Knockout结合Bootstrap创建动态UI--产品列表管理
本篇文章结合Bootstrap创建一个比较完整的应用,对产品列表进行管理,包括产品的增加.删除.修改. 需要的引用 <script type='text/javascript' src='htt ...
- 原生javascript-无间缝滚动,封装
目前支持的是竖向与横向滚动 http://lgy.1zwq.com/marScroll/ 现在分析下无间缝实现的基本思路(竖向例子): HTML结构: <div id="marScro ...
- 文件上传及时显示, 前端js和后端php相互结合使用
文件读取 javascript 绑定文件上传变化事件 onchange 利用window对象 FileReader 调用方法 readerAsDataURL onload 方法 异步读取 属性:fil ...
- 【zznu-夏季队内积分赛3-J】追忆
题目描述 “别人总说我瓜,其实我一点也不瓜,大多数时候我都机智的一批“现在是阳历2018/8/7,宝儿姐想起自己参加ACM整整1000天了.她想知道她刚入坑是什么时间.那么问题来了,请帮宝儿姐追忆一下 ...
- Windows 下 左Ctrl和Caps交换
将以下文本存为后缀为.reg文件,运行并重启即可 左Ctrl和Caps交换 Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTE ...
- CMDB开发(需求分析)
浅谈ITIL TIL即IT基础架构库(Information Technology Infrastructure Library, ITIL,信息技术基础架构库)由英国政府部门CCTA(Central ...
- 【html5】hashchange Event – 监测URL的hash变化
通过URL传值,在?后附加以=连接的键值对,各键值对间以&连接:也可以通过URL传递页面参数,在”#”后附加的方式.两者最大的一个 区别在于:后者不会发起请求,不会导致页面刷新.常见应用场景在 ...
- Apache .htaccess文件
今天在将ThinkPHP的URL模式由普通模式(URL_MODE=1)http://localhost/mythinkphp/index.php/Index/user/id/1.html改为重写模式 ...