022configparser模块
#配置模块
#创建
import configparser
config = configparser.ConfigParser()
#添加
config["DEFAULT"] = {'ServerAliveInterval':'45',
'Compression':'yes',
'CompressionLevel':'9'}
config['bitbucket.org'] = {'User':'hg'}
#config['bitbucket.org']={}
#config['bitbucket.org']['User']='hg'
config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['HostPort'] = '50022'#mutatestheparser
topsecret['ForwardX11'] = 'no'#samehere
config['DEFAULT']['ForwardX11'] = 'yes'
#通过下面这个写入到文件
with open('example.ini','w') as configfile:
config.write(configfile)
#读取
config.read('example.ini')
print(config.sections()) # ['bitbucket.org','topsecret.server.com']
print(config.default_section) # DEFAULT
print(config.defaults())#OrderedDict([('serveraliveinterval','45'),('compression','yes'),('compressionlevel','9'),('forwardx11','yes')])
print(config['bitbucket.org']['User']) # hg
for key in config['bitbucket.org']: # 和for key in config: 有区别
print(key)
#user
#serveraliveinterval
#compression
#compressionlevel
#forwardx11
# 删除
config.remove_section('topsecret.server.com') # 没有办法改原来的文件
config.write(open('i.cfg','w')) # 重新生成一个文件
config.remove_option('bitbucket.org','user')
# 判断是否存在
print(config.has_section('topsecret.server.com'))
#更改
config.set('bitbucket.org','user','aiq')
config.write(open('example.ini','w'))
###凡是更改了里面的内容都需要重新写入
022configparser模块的更多相关文章
- npm 私有模块的管理使用
你可以使用 NPM 命令行工具来管理你在 NPM 仓库的私有模块代码,这使得在项目中使用公共模块变的更加方便. 开始前的工作 你需要一个 2.7.0 以上版本的 npm ,并且需要有一个可以登陆 np ...
- node.js学习(三)简单的node程序&&模块简单使用&&commonJS规范&&深入理解模块原理
一.一个简单的node程序 1.新建一个txt文件 2.修改后缀 修改之后会弹出这个,点击"是" 3.运行test.js 源文件 使用node.js运行之后的. 如果该路径下没有该 ...
- ES6模块import细节
写在前面,目前浏览器对ES6的import支持还不是很好,需要用bable转译. ES6引入外部模块分两种情况: 1.导入外部的变量或函数等: import {firstName, lastName, ...
- Python标准模块--ContextManager
1 模块简介 在数年前,Python 2.5 加入了一个非常特殊的关键字,就是with.with语句允许开发者创建上下文管理器.什么是上下文管理器?上下文管理器就是允许你可以自动地开始和结束一些事情. ...
- Python标准模块--Unicode
1 模块简介 Python 3中最大的变化之一就是删除了Unicode类型.在Python 2中,有str类型和unicode类型,例如, Python 2.7.6 (default, Oct 26 ...
- Python标准模块--Iterators和Generators
1 模块简介 当你开始使用Python编程时,你或许已经使用了iterators(迭代器)和generators(生成器),你当时可能并没有意识到.在本篇博文中,我们将会学习迭代器和生成器是什么.当然 ...
- 自己实现一个javascript事件模块
nodejs中的事件模块 nodejs中有一个events模块,用来给别的函数对象提供绑定事件.触发事件的能力.这个别的函数的对象,我把它叫做事件宿主对象(非权威叫法),其原理是把宿主函数的原型链指向 ...
- 理解nodejs模块的scope
描述 原文档地址:https://docs.npmjs.com/misc/scope 所有npm模块都有name,有的模块的name还有scope.scope的命名规则和name差不多,同样不能有ur ...
- nodejs模块发布及命令行程序开发
前置技能 npm工具为nodejs提供了一个模块和管理程序模块依赖的机制,当我们希望把模块贡献出去给他人使用时,可以把我们的程序发布到npm提供的公共仓库中,为了方便模块的管理,npm规定要使用一个叫 ...
随机推荐
- Boost application performance using asynchronous I/O-ref
http://www.ibm.com/developerworks/linux/library/l-async/?S_TACT=105AGX52&S_CMP=cn-a-l Introducti ...
- MySQL 5.6内存占用过高解决方案
距离MySQL 5.6正式发布已经有比较长的时间了,目前Oracle官网上的最新GA版本MySQL server也为5.6.但reizhi在安装配置后却发现其内存占用居高不下,无论如何调整cach ...
- [转]Add Bootstrap Glyphicon to Input Box
本文转自:http://stackoverflow.com/questions/18838964/add-bootstrap-glyphicon-to-input-box How can I add ...
- D3基础---比例尺
转载请注明出处! 比例尺简述: 比例尺是一组把输入域映射到输出范围的函数. 一般来说数据集中的值不可能恰好与图表中的像素尺度一一对应.比例尺就是把这些数据值映射到可视化图形中使用的新值的便捷手段. D ...
- nodejs常用npm包
express常用npm包整理如下 art-template 一款js模板引擎,性能不错 jayson 一款纯node的rpc应用包,可实现rpc服务.tcp.http等服务 multer ...
- js 表格合并单元格
5列 根据需要可添加 或 删除 strOneTemp strTwoTemp strThreeTemp strFourTemp strFiveTemp //合并单元格 this.mergeC ...
- unity3d之切换场景不销毁物体
using System.Collections; using System.Collections.Generic; using UnityEngine; /// <summary> / ...
- 小白学flask之静态文件
引入css的方式有两种 1 那在flask中,如何处理静态文件? 做法很简单,只要在你的包或模块旁边创建一个名为 static 的文件夹就行了. flask的静态文件是位于应用的 /static 中的
- 廖雪峰JavaScript练习题2
请把用户输入的不规范的英文名字,变为首字母大写,其他小写的规范名字.输入:['adam', 'LISA', 'barT'],输出:['Adam', 'Lisa', 'Bart'] 肯定有更简单的方法, ...
- 警告: The web application [ROOT] appears to have started a thread named [Thread-48] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
1. 问题描述 tomcat跑web项目(其中依赖java项目) 出现大量上述警告 项目起不来 关键字 memory leak 内存泄漏 2. 解决方案 难道是程序写的有问题? 最终 将tomcat ...