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 > ...
随机推荐
- Angular2-使用Augury来调试Angular2程序
参考: http://www.jianshu.com/p/efecaea287f2https://augury.angular.io/ https://augury.angular.io/pages/ ...
- JSP 发送邮件
JSP 发送邮件 虽然使用JSP实现邮件发送功能很简单,但是需要有JavaMail API,并且需要安装JavaBean Activation Framework. 在这里下载最新版本的 JavaMa ...
- 什么是JSON?
JSON是一种取代XML的数据结构,和xml相比,它更小巧但描述能力却不差,由于它的小巧所以网络传输数据将减少更多流量从而加快速度. JSON就是一串字符串 只不过元素会使用特定的符号标注. {} 双 ...
- Android Kotlin —— 语言结合
2017 Google I/O 大会开始就宣布,将Kotlin语言作为安卓开发的一级编程语言. Kotlin 是一个基于 JVM 的新的编程语言,由 JetBrains 开发. Ko ...
- fio测试freenas共享的iscsi磁盘性能
4k随机读iops: fio -ioengine=libaio -bs=4k -direct=1 -thread -rw=randread -filename=/dev/sdb -iodepth=32 ...
- vue iview组件表格 render函数的使用
如果要在标签中加入属性,例如img 中src属性 a标签中href属性 此时需要用到 attrs 来加入而不是props { title: '操作', key: 'action', align: 'c ...
- phpMyAdmin 应用程序“DEFAULT WEB SITE”中的服务器错误
分析原因:没有“C:\inetpub\wwwroot\phpmyadmin\”此目录 解决办法:新建路径 分析原因:IIS设置少了一项,需添加"服务端包含"选项 解决办法:控制面板 ...
- CSS布局 — 圣杯布局与双飞翼布局
圣杯布局 实现原理 html代码中,middle部分首先要放在container的最前部分,然后是left,right 将三者都设置 float:left, position:relative (因为 ...
- 二十三、DBMS_METADATA(提供提取数据库对象的完整定义的接口)
1.概述 作用:提供提取数据库对象的完整定义的接口.这些定义可以用XML或SQL DDL格式描述.提供两种类型接口:可编程控制的接口:用于Ad Hoc查询的简单接口. 2.包的组成 dbms_meta ...
- 软件测试模型---V模型、W模型、H模型、X模型
人活着一定要有目标,确定自己喜欢什么,再坚持做下去,那么他过得一定不会太差. 煽情的话,不多说,本文主要讲解:"软件测试模型-V模型.W模型.H模型.X模型". 1.V模型 V模型 ...