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 > ...
随机推荐
- SQL Server配置管理器”远程过程调用失败“
在设置服务器远程连接的时候,打开SQL server配置管理器时,SQL server服务右侧显示“远程调用失败”. 解决方法: 在控制面板中找到 Microsoft SQL Server 2016 ...
- String类的subString(a,b)方法(基于jdk 1.9)
基于上文:http://www.jianshu.com/p/a20ee3bb9c1b public String substring(int beginIndex, int endIndex) { i ...
- Java的优势
Java是一种跨平台,适合于分布式计算环境的面向对象编程语言. 具体来说,它具有如下特性: 简单性.面向对象.分布式.解释型.可靠.安全.平台无关.可移植.高性能.多线程.动态性等. 下面我们将重点介 ...
- Shell_NotifyIcon托盘图标闪烁
之前的同事留下了一个程序会莫名闪退的bug,今天终于发现是托盘图标闪烁使得gdi资源耗尽导致的. 先定义 #include "shellapi.h" //托盘图标引用 NOTIFY ...
- confluence wiki 破解安装操作流程
准备postgres数据库安装 步骤1:命令: docker pull postgres 步骤2:安装: docker run --name postgresdb -p 5432:5432 -e PO ...
- Jdev 本地RUN页面时候,将异常直接显示出来,而不是乱码
本地运行页面时,经常会遇到以下错误 oracle.jbo.JboException: JBO-29000: JBO-29000: JBO-26028: ???? MemberAttributesDis ...
- taskset -pc PID 查看线程占用cpu核
taskset -pc PID 可以用于 查看 当前线程 对应绑定的 在 哪个核上面. 这个 可以用于 程序优化, 查看 哪个线程占用的 cpu 比重比较高 首先 可以通过 top -H - ...
- caffe:自己搭建网络来训练
1.准备样本 要训练自己的样本,首先需要把样本准备好,需要准备的是训练集和测试集,caffe支持直接使用图片,当然把样本转换为leveldb或lmdb格式的话训练起来会更快一点.这里我先偷个懒,直接使 ...
- C#中Abstract和Virtua笔记,知识
在C#的学习中,容易混淆virtual方法和abstract方法的使用,现在来讨论一下二者的区别.二者都牵涉到在派生类中与override的配合使用. 一.Virtual方法(虚方法) virtual ...
- resizable可调整尺寸组件
Resizable 可调整尺寸不依赖于其他组件 1.用法:通过标记创建可调整尺寸(resizable)对象 <div class="easyui-resizable" sty ...