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 > ...
随机推荐
- python学习笔记(字典乱码)
博主总结下 python中字典中包含中文时,使用过程中出现乱码 json.dumps(params, encoding="UTF-8", ensure_ascii=False) p ...
- 利用python 模块读取csv文件信息
还有一个比较简单的方法 # -*- coding=utf-8 -*- import pandas as pddf = pd.read_csv("20170320094630.csv" ...
- Docker总结
Docker总结 一.Docker简介 1.问题:为什么会有docker出现 一款产品从开发到上线,从操作系统,到运行环境,再到应用配置.作为开发+运维之间的协作我们需要关心很多东西,这也是很多互联网 ...
- 十六 web爬虫讲解2—PhantomJS虚拟浏览器+selenium模块操作PhantomJS
PhantomJS虚拟浏览器 phantomjs 是一个基于js的webkit内核无头浏览器 也就是没有显示界面的浏览器,利用这个软件,可以获取到网址js加载的任何信息,也就是可以获取浏览器异步加载的 ...
- 【收藏】SQL多行变一列
CREATE TABLE DEPT (DeptNo INT IDENTITY(1, 1)NOT NULL , Country VARCHAR(50) , Location VARCHAR(50) ...
- Pytorch入门笔记
import torch.nn as nn import torch.nn.functional as F class Net(nn.Module): def __init__(self): #nn. ...
- Python -- 使用pickle 和 CPickle对数据对象进行归档和解析
经常遇到在Python程序运行中得到了一些字符串.列表.字典.对象等数据,想要长久的保存下来,方便以后使用,而不是简单的放入内存中关机断电就丢失数据. 这个时候Pickle模块就派上用场了,它可以将对 ...
- spring中aop使用
AOP为Aspect Oriented Programming的缩写,意为:面向切面编程AOP采取横向抽取机制,取代了传统纵向继承体系重复性代码(性能监视.事务管理.安全检查.缓存) Spring的基 ...
- c# 三种取整方法 向上取整 向下取整 四舍五入
Math.Round:四舍六入五取整 Math.Ceiling:向上取整,只要有小数都加1 Math.Floor:向下取整,总是舍去小数
- 【sql】使用触发器
今天在写sql触发器时遇到这样一个问题: 利用完整性规则创建教师表,包括(教师工号,姓名,性别,职称,工资),在此基础上定义触发器,为教师表Teacher定义完整性规则“教授的工资不能低于4000元, ...