day31 configparser 配置文件模块
#__author__: Administrator
#__date__: 2018/8/8
# configparse 生成配置文件,配置文会以件.ini结尾
# 对于格式有要求
# 创建配置文档
import configparser
config = configparser.ConfigParser()
config["DEFAULT"] = {'ServerAliveInterval': '',
'Compression': 'yes',
'CompressionLevel': '',
'ForwardX11':'yes'
}
config['bitbucket.org'] = {'User':'hg'} config['topsecret.server.com'] = {'Host Port':'','ForwardX11':'no'} with open('example.ini', 'w') as f:
config.write(f) # import configparser
# config = configparser.ConfigParser()
#---------------------------查找文件内容,基于字典的形式
# print(config.sections()) # [] 读组信息,但是没有指定到底读哪个文件,尽管不报错,但是读出来是空 # config.read('example.ini') # 选取要读取的文件
# print(config.sections()) # ['bitbucket.org', 'topsecret.server.com'] [DEFAULT]会不显示 # print('bytebong.com' in config) # False 判断组在不在文件里面
# print('bitbucket.org' in config) # True
#
# print(config['bitbucket.org']["user"]) # hg 查找文件的组内的某个项的内容
# print(config['DEFAULT']['Compression']) # yes [DEFAULT]里面也是可以拿出来的
# print(config['topsecret.server.com']['ForwardX11']) # no
#
# print(config['bitbucket.org']) #<Section: bitbucket.org> 打印出来地址,没什么用
#
# for key in config['bitbucket.org']: # 注意,有default会默认default的键
# print(key)
#
# print(config.options('bitbucket.org')) # 同for循环,找到'bitbucket.org'下所有键
#
# print(config.items('bitbucket.org')) #找到'bitbucket.org'下所有键值对
#
# print(config.get('bitbucket.org','compression')) # yes get方法Section下的key对应的value # 增加更改删除
# import configparser
# config = configparser.ConfigParser()
# config.read('example.ini') # 读文件
# config.add_section('yuan') # 增加section
# config.remove_section('bitbucket.org') # 删除一个section
# config.remove_option('topsecret.server.com',"forwardx11") # 删除一个配置项
# config.set('topsecret.server.com','k1','11111')
# config.set('yuan','k2','22222')
# f = open('new2.ini', "w")
# config.write(f) # 写进文件
# f.close()
[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forwardx11 = yes [bitbucket.org]
user = hg [topsecret.server.com]
host port = 50022
forwardx11 = no
day31 configparser 配置文件模块的更多相关文章
- configparser 配置文件模块
#_author:star#date:2019/11/7# configparser 配置文件模块import configparserconfig=configparser.ConfigParser ...
- configparser配置文件模块
1.configparser的作用 mysql等很多文件的配置如下: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLeve ...
- hashlib摘要算法模块,logging日志,configparser配置文件模块
一.hashlib模块(摘要算法模块) 1.算法介绍 Python的hashlib提供了常见的摘要算法,如MD5,SHA1等等. 什么是摘要算法呢? 摘要算法又称哈希算法.散列算法.它通过一个函数,把 ...
- configparser (配置文件) 模块
主要内容来自景女神博客 内涵:该模块适用于配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 常见文档格式: [DEFAULT] ...
- 面向对象总结、configparser配置文件模块、logging日志模块
面向对象总结 # 学习态度# python基础 2个月# html css js jq 1个月 # 上课困 # 学习方法 :# 列出知识点# 例子 写了哪些 # 面向对象学了哪些块# 为什么要讲面向对 ...
- Python之配置文件模块 ConfigParser
写项目肯定用的到配置文件,这次学习一下python中的配置文件模块 ConfigParser 安装就不说了,pip一下即可,直接来个实例 配置文件 project.conf [db] host = ' ...
- s14 第5天 时间模块 随机模块 String模块 shutil模块(文件操作) 文件压缩(zipfile和tarfile)shelve模块 XML模块 ConfigParser配置文件操作模块 hashlib散列模块 Subprocess模块(调用shell) logging模块 正则表达式模块 r字符串和转译
时间模块 time datatime time.clock(2.7) time.process_time(3.3) 测量处理器运算时间,不包括sleep时间 time.altzone 返回与UTC时间 ...
- 第四十二节,configparser特定格式的ini配置文件模块
configparser用于处理特定格式的文件,其本质上是利用open来操作文件. 特定格式的ini配置文件模块,用于处理ini配置文件,注意:这个ini配置文件,只是ini文件名称的文本文件,不是后 ...
- Python模块之: ConfigParser 配置文件读取
Python模块之: ConfigParser 配置文件读取 ConfigParser用于读写类似INI文件的配置文件,配置文件的内容可组织为组,还支持多个选项值(option-value)类型. ...
随机推荐
- 讲一下Asp.net core MVC2.1 里面的 ApiControllerAttribute (转载)
ASP.NET Core MVC 2.1 特意为构建 HTTP API 提供了一些小特性,今天主角就是 ApiControllerAttribute. (注:文章是18年2月份的,所以文章提到了cor ...
- Vue-接口跨域请求调试proxyTable
在项目开发的时候,接口联调的时候一般都是同域名下,且不存在跨域的情况下进行接口联调,但是当我们现在使用vue-cli进行项目打包的时候,我们在本地启动服务器后,比如本地开发服务下是 http://lo ...
- [HNOI2018]排列[堆]
题意 给定一棵树,每个点有点权,第 \(i\) 个点被删除的代价为 \(w_{p[i]}\times i\) ,问最小代价是多少. 分析 与国王游戏一题类似. 容易发现权值最小的点在其父亲选择后就会立 ...
- 如何用区块链技术解决信任问题?Fabric 架构深度解读
阿里妹导读:区块链技术,随着比特币的兴起而为大家所知.但是具体到技术本身,大家相对熟悉的几个词可能是“数据不可篡改”.“公开链”.“分布式数据”.“共识机制”等. 这篇文章将抛砖引玉,通过深度解读Hy ...
- ETL流程介绍及常用实现方法
ETL是英文Extract-Transform-Load 的缩写,用来描述将数据从来源端经过抽取(extract).转换(transform).加载(load)至目的端的过程.常见于数据仓库开发中将数 ...
- 微服务之Sping Cloud
版本说明 Finchley SR2 价值简要 微服务之间是松耦合,跨不同业务部门,提供非常充分的灵活性,加快项目开发完成效率,方便组件化独立可扩展性及复用. 微服务应用结构表现 组件简要 1. Eur ...
- C#_获取路径
一.获取当前文件的路径 1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName 获取模块的完整路径,包括文件名. ...
- linux-流程控制语言
if: for: 增强for循环 while: 统计这个目录下所有文件的大小 编写脚本 执行 help text:
- pair work结对编程(张艺 杨伊)
一.结对编程人员: 张艺(学号后三位:185) 杨伊(学号后三位:151) 二.这是我们工作的样子:(图片) 三.结对编程优缺点: 优点: 1.结对编程时间紧密,在一定程度上可以督促双方学习,提高 ...
- 关于本科毕业论文《Laguerre小波在数值积分与微分方程数值解中的应用》存在的问题与小结
本科的毕业设计<Laguerre小波在数值积分与微分方程数值解中的应用>是通过Laguerre小波函数来近似表达某个需要求积分或解微分方程的函数,将原函数很难求得函数用小波函数表达出来,这 ...