一、创建文件

 ##-----------------创建数据表--------------------------
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的更多相关文章

  1. Python模块之configpraser

    Python模块之configpraser   一. configpraser简介 用于处理特定格式的文件,其本质还是利用open来操作文件. 配置文件的格式: 使用"[]"内包含 ...

  2. python 学习第五天,python模块

    一,Python的模块导入 1,在写python的模块导入之前,先来讲一些Python中的概念性的问题 (1)模块:用来从逻辑上组织Python代码(变量,函数,类,逻辑:实现一个功能),本质是.py ...

  3. python模块介绍- multi-mechanize 性能测试工具

    python模块介绍- multi-mechanize 性能测试工具 2013-09-13 磁针石 #承接软件自动化实施与培训等gtalk:ouyangchongwu#gmail.comqq 3739 ...

  4. python模块:网络协议和支持

    python模块:网络协议和支持 webbrowser 调用浏览器显示html文件 webbrowser.open('map.html') [webbrowser - Convenient Web-b ...

  5. python模块部分----模块、包、常用模块

    0.来源:https://www.cnblogs.com/jin-xin/articles/9987155.html 1.导入模块 1.1模块就是一个python文件,模块名是文件名 1.2导入模块的 ...

  6. python模块之_正则 re_configparser_logging_hashlib

    正则表达式的内容放在最下面了 configparser 模块: #!/usr/bin/env python # coding:utf-8 import configparser # 专门用于操作配置文 ...

  7. 【转】python模块分析之logging日志(四)

    [转]python模块分析之logging日志(四) python的logging模块是用来写日志的,是python的标准模块. 系列文章 python模块分析之random(一) python模块分 ...

  8. python 模块之-configparser

    python 模块configparser   配置文件模块 import configparser    config = configparser.ConfigParser() config[&q ...

  9. python 模块之-logging

    python  模块logging import logging ###  简单使用格式    日志级别等级CRITICAL > ERROR > WARNING > INFO > ...

随机推荐

  1. 《Think in Java》(十一)持有对象

    Java 中的持有对象就是容器啦,看完这一章粗略的了解了 Java 中的容器框架以及常用实现!但是容器框架中的接口以及实现类有好多,下午还得好好看看第 17 章--容器深入研究以及 Java 官方的文 ...

  2. 仅需15分钟,使用OpenCV+Keras轻松破解验证码

    https://baijia.baidu.com/s?id=1586732712477979223&wfr=pc&fr=app_lst

  3. Java连接MySQL数据库——代码

    工具:eclipse MySQL5.7.17 MySQL连接驱动:mysql-connector-java-5.1.43.jar 加载驱动:我是用MAVEN进行管理 数据库连接信息: 数据库名称:wu ...

  4. office套件

    一.PDF模块 使用PyPDF2模块 pip install PyPDF2 1.1 从PDF读取数据 直接读取,并打印出来.但是这种打印存在一个问题,不能中文字符 import PyPDF2 impo ...

  5. SQL HAVING用法详解

    来自:http://blog.csdn.net/wozeze1/article/details/6031318 HAVING 子句对 GROUP BY 子句设置条件的方式与 WHERE 和 SELEC ...

  6. Mac上安装第三方应用显示包资源破坏解决办法

    Mac上安装第三方应用显示包资源破坏解决办法 步骤1:Spotlight搜索(快捷键:command+空格或右上角搜索的符号):搜索 “终端”步骤2:直接复制粘贴 sudo spctl --maste ...

  7. Linux:grub密码设置与修改

    grub密码设置与修改 默认GRUB启动参数可以的进入单用户模式从而修改root密码,如果想要给GRUB菜单设置密码,可以修改/etc/grub.conf文件 (/boot/grub/grub.con ...

  8. [Err] 1449 - The user specified as a definer ('student'@'%') does not exist

    1.错误描述 [SQL]use student; 受影响的行: 0 时间: 0.001s [SQL] call alter_student('t_student','MODIFY COLUMN `we ...

  9. 桶排序bucket sort

    桶排序 (Bucket sort)或所谓的箱排序的原理是将数组分到有限数量的桶子里,然后对每个桶子再分别排序(有可能再使用别的排序算法或是以递归方式继续使用桶排序进行排序),最后将各个桶中的数据有序的 ...

  10. vue中使用less

    我们需要下载less对应的依赖包 第一步: 安装less依赖,npm install less less-loader --save 第二步: 修改webpack.config.js文件,配置load ...