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)类型. ...
随机推荐
- oracle 相除后保留指定位数小数round()
) xxx from dual; XXX---------- 3.8871
- 浅析单点登录,以及不同二级域名下的SSO实现
一家公司有多个产品线,就可能要有多个子域名,下头以baidu域名为例,a.baidu.com, b.baidu.com.com 是顶级域名,baidu 就是一个二级域名,a和b就是子域名. 当用户在a ...
- Redis详解(六)------ RDB 持久化
前面我们说过,Redis 相对于 Memcache 等其他的缓存产品,有一个比较明显的优势就是 Redis 不仅仅支持简单的key-value类型的数据,同时还提供list,set,zset,has ...
- webstorm破解汉化
一.下载webstorm软件和汉化包 webstorm安装包下载链接 : 链接: https://pan.baidu.com/s/1VmOPNVL2GRgAb_0tAJhy8A 密码: am7e 汉化 ...
- POJ1845
这还是一道综合了许多数论的知识点的,做完也涨了不少姿势 但还是因为约数和公式这个鬼东西去找了度娘 题意很简单,就是求\(A^B\)的约数之和\(mod\ 9901\). 但是这种题意越是简单的题目越是 ...
- CF1153F Serval and Bonus Problem FFT
CF1153F Serval and Bonus Problem 官方的解法是\(O(n ^ 2)\)的,这里给出一个\(O(n \log n)\)的做法. 首先对于长度为\(l\)的线段,显然它的答 ...
- python中和生成器协程相关的yield之最详最强解释,一看就懂(一)
yield是python中一个非常重要的关键词,所有迭代器都是yield实现的,学习python,如果不把这个yield的意思和用法彻底搞清楚,学习python的生成器,协程和异步io的时候,就会彻底 ...
- Docker(三):Dockerfile 命令详解
上一篇文章Docker(二):Dockerfile 使用介绍介绍了 Dockerfile 的使用,这篇文章我们来继续了解 Dockerfile ,学习 Dockerfile 各种命令的使用. Dock ...
- Linux下对文件进行加密备份的操作记录
由于公司之前在阿里云上购买了一些机器,后续IDC建设好后,又将线上业务从阿里云上迁移到IDC机器上了,为了不浪费阿里云上的这几台机器资源,打算将这些机器做成IP SAN共享存储,然后作为IDC数据的一 ...
- MariaDB第三章(select)
基本查询 --查询基本使用(条件,排序,聚合函数,分组,分页) --创建学生表 create table students ( id int unsigned not null auto_increm ...