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 ...
随机推荐
- Python:时间日历基本处理
time 模块 提供了处理时间和表示之间转换的功能 获取当前时间戳 时间戳:从0时区的1970年1月1日0时0分0秒,到所给定日期时间的时间,浮点秒数,或者毫秒整数 获取方式: import time ...
- 15. 深入解析Pod对象(二):使用进阶
15. 深入解析Pod对象(二):使用进阶 15.1 Projected Volume,投射数据卷 备注:Projected Volume 是 Kubernetes v1.11 之后的新特性 在 Ku ...
- 连接数据库的url
mysql: jdbc:mysql://localhost:3306:test这句里面分如下解析:jdbc:mysql:// 是指JDBC连接方式:localhost: 是指你的本机地址:3306 S ...
- cf854B Maxim Buys an Apartment
Maxim Buys an Apartment #include <iostream> #define int long long using namespace std; int n,k ...
- Python学习第二十三课——Mysql 表记录的一些基本操作 (查)
查(select * from 表名) 基本语法: select <字段1,字段2,...> from <表名> where <表达式>; 例如,查询student ...
- PCSearch
1.hinstance:GetModuleHandle(NULL) 2.窗口直角: 方法1:在Oncreate函数中添加以下代码,然而这种方法会导致窗口阴影无效 LONG styleValue = : ...
- jmeter 并发控制
1.吞吐控制器以线程组的请求sampler为控制对象, 2.事务控制器: 3.同步定时器syn timer:对某线程组下任意的sampler任意位置作用为,有序控制单个sampler的并发先sampl ...
- [IDEA] Idea复制文件到项目一直updating indices的问题
通常我们在开发JavaWeb项目的时候,都需要先将网页写好,在进行复制到web目录下,如果里面包含了很多的资源文件,就会造成一直updating indices. 方法一: 这是因为项目需要对web目 ...
- python 连接oracle基础环境配置方法
配置基础: 1.python3.7 2.oracle server 11g 64位 3.PLSQL 64位 4.instantclient-basic-windows.x64-11.2.0.4.0这个 ...
- DVWA靶机的命令执行漏洞
之前在打攻防世界的时候出现过类似的题目,这里再重温一下 (靶机一共低中高三个安全等级,这里只演示低中等级) (1)Security:low 根据提示让我们输入地址ping一下,之后返回以下内容,可以判 ...