re模块补充 configparse模块
import re
re.findall("(?:abc)+","abcabcabc")
--->['abcabcabc']
import configparser
config = configparser.ConfigParser() #创建配置文件,config = {}相当于一个字典 config["default"] = {'ServerAliveInterval':45,
'Compression':'yes',
'CompressionLevel':''} config['bitbucket.org'] = {}
config['bitbucket.org']['User'] = 'zsz' config['topsecret.server.com'] = {}
topsecret = config['topsecret.server.com']
topsecret['Host Port'] = ''
topsecret['ForwardX11'] = 'no' with open('example.ini','w') as f:
config.write(f)
f.close()
#----------------------------------------------增删改查------------------------------------------------------------
#查
config = configparser.ConfigParser()
config.read('example.ini')
print(config.sections()) #得到所有的块
--->['default', 'bitbucket.org', 'topsecret.server.com']
print('bytebong.com' in config) #判断块中是否有bytebong.com
--->False
print(config['bitbucket.org']['User'])
--->zsz
print(config['default']['compression'])
--->yes
print(config['topsecret.server.com']['forwardx11'])
--->no
for key in config['bitbucket.org']: #取'bitbucket.org'下所有的键
print(key)
--->user
print(config.options('default')) #取键
--->['serveraliveinterval', 'compression', 'compressionlevel']
print(config.items('default')) #得到块下的键值对
--->[('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9')]
print(config.get('default','compression')) #得到对应键的值
--->yes #删,改,查
config.add_section('yuan') #增加块
config.set('yuan','k1','') #添加键值对
config.remove_section('topsecret.server.com') #删除块
config.remove_option('default','compression') #删除块下的键值对
config.write(open('example.ini','w')) #这么写不用关闭文件
re模块补充 configparse模块的更多相关文章
- 0423 hashlib模块、logging模块、configparse模块、collections模块
一.hashlib模块补充 1,密文验证 import hashlib #引入模块 m =hashlib.md5() # 创建了一个md5算法的对象 m.update(b') print(m.hexd ...
- Python进阶-XVV hashlib模块、configparse模块、logging模块
1.配置相关的configparse模块 配置文件如何组织?python中常见的是将配置文件写成py,然后引入该模块即可.优点是方便访问. 但是也有用类似windows中的ini文件的配置文件,了解即 ...
- Python学习日记(二十八) hashlib模块、configparse模块、logging模块
hashlib模块 主要提供字符加密算法功能,如md5.sha1.sha224.sha512.sha384等,这里的加密算法称为摘要算法.什么是摘要算法?它又称为哈希算法.散列算法,它通过一个函数把任 ...
- python模块之configparse模块
# -*- coding:utf-8 -*- import configparser # configparser 模块 # 1.创建一个创建对象 # 2.创建键值对的配置项目 字典的形式进行创建 # ...
- 文成小盆友python-num7 -常用模块补充 ,python 牛逼的面相对象
本篇内容: 常用模块的补充 python面相对象 一.常用模块补充 1.configparser模块 configparser 用于处理特定格式的文件,起内部是调用open()来实现的,他的使用场景是 ...
- Java 200+ 面试题补充③ Dubbo 模块
昨天在我的 Java 面试粉丝群里,有一个只有一年开发经验的小伙伴只用了三天时间,就找到了一个年薪 20 万的工作,真是替他感到开心. 他的经历告诉我们:除了加强自我实战经验之外,还要努力积累自己的理 ...
- Java 200+ 面试题补充② Netty 模块
让我们每天都能看到自己的进步.老王带你打造最全的 Java 面试清单,认真把一件事做到最好. 本文是前文<Java 最常见的 200+ 面试题>的第二个补充模块,第一模块为:<Jav ...
- python configparse模块&xml模块
configparse模块 用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. [DEFAULT] serveraliveinterval = ...
- 【转】Python3 configparse模块(配置)
[转]Python3 configparse模块(配置) ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(s ...
随机推荐
- opencv python:模糊操作
均值模糊 中值模糊 自定义模糊 模糊操作的基本原理 基于离散卷积 定义好每个卷积核 不同卷积核得到不同的卷积效果 模糊是卷积的一种表象 blur cv2.blur(image, (1, 3)) 第二个 ...
- python opencv:绘图 基本图形
参数说明 • img:你想要绘制图形的那幅图像. • color:形状的颜色.以 RGB 为例,需要传入一个元组,例如:( 255,0,0)代表蓝色.对于灰度图只需要传入灰度值. • thicknes ...
- Codeforces Round #619 (Div. 2) B. Motarack's Birthday
Dark is going to attend Motarack's birthday. Dark decided that the gift he is going to give to Motar ...
- proto school tutorial: blog: lesson 1
https://proto.school/#/blog/01 我们现在希望:把一个post 和他的作者联系起来. 从之前的教程here中,你可以知道, 一个cid 就是代表一个link 比如: { l ...
- 根据class 属性判断所有的文本框必填
<body> <!-- 遮罩层 --> <div id="hidediv" style="width: 100%;height: 100%; ...
- 刚下载好的 vscode 不能运行,一片黑 以及终端不能输入 解决办法
1.鼠标右键vscode快捷方式点击属性,选择兼容性,勾选以兼容模式运行,下拉列表调整为windows vista (service pack 1)即可解决. 2.如果打开终端不能输入命令,首先点击属 ...
- re.compile匹配
import re string = '<h4 class="title">愤怒的葡萄</h4>' pattern = '<h4 class=&quo ...
- Python - unittest打印成功信息
参考 https://stackoverflow.com/questions/36834677/print-success-messages-for-asserts-in-python 总结 clas ...
- ROS-debug1 : 运行roscore时报错:Unable to contact my own server at...
一.问题描述 在终端运行roscore时,出现错误:Unable to contact my own server at...,如下图: 二.解决方法 以上问题是由于ROS环境变量ROS_MASTER ...
- Windows程序设计学习笔记(1):一个简单的windows程序
<Windows程序设计>(第五版)(美Charles Petzold著) #include<windows.h> LRESULT CALLBACK WndProc(HWND, ...