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模块的更多相关文章

  1. 0423 hashlib模块、logging模块、configparse模块、collections模块

    一.hashlib模块补充 1,密文验证 import hashlib #引入模块 m =hashlib.md5() # 创建了一个md5算法的对象 m.update(b') print(m.hexd ...

  2. Python进阶-XVV hashlib模块、configparse模块、logging模块

    1.配置相关的configparse模块 配置文件如何组织?python中常见的是将配置文件写成py,然后引入该模块即可.优点是方便访问. 但是也有用类似windows中的ini文件的配置文件,了解即 ...

  3. Python学习日记(二十八) hashlib模块、configparse模块、logging模块

    hashlib模块 主要提供字符加密算法功能,如md5.sha1.sha224.sha512.sha384等,这里的加密算法称为摘要算法.什么是摘要算法?它又称为哈希算法.散列算法,它通过一个函数把任 ...

  4. python模块之configparse模块

    # -*- coding:utf-8 -*- import configparser # configparser 模块 # 1.创建一个创建对象 # 2.创建键值对的配置项目 字典的形式进行创建 # ...

  5. 文成小盆友python-num7 -常用模块补充 ,python 牛逼的面相对象

    本篇内容: 常用模块的补充 python面相对象 一.常用模块补充 1.configparser模块 configparser 用于处理特定格式的文件,起内部是调用open()来实现的,他的使用场景是 ...

  6. Java 200+ 面试题补充③ Dubbo 模块

    昨天在我的 Java 面试粉丝群里,有一个只有一年开发经验的小伙伴只用了三天时间,就找到了一个年薪 20 万的工作,真是替他感到开心. 他的经历告诉我们:除了加强自我实战经验之外,还要努力积累自己的理 ...

  7. Java 200+ 面试题补充② Netty 模块

    让我们每天都能看到自己的进步.老王带你打造最全的 Java 面试清单,认真把一件事做到最好. 本文是前文<Java 最常见的 200+ 面试题>的第二个补充模块,第一模块为:<Jav ...

  8. python configparse模块&xml模块

    configparse模块 用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser. [DEFAULT] serveraliveinterval = ...

  9. 【转】Python3 configparse模块(配置)

    [转]Python3 configparse模块(配置) ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(s ...

随机推荐

  1. vs2019本地调试异步程序

    1.vs2019创建一个webapi服务,启动本地webapi服务, 2.使用vs2019再打开一个相同的应用程序,并将异步程序所在的程序集设置为启动项,并启动,启动后点击调试->全部拆离 3. ...

  2. 吴裕雄--天生自然TensorFlow2教程:激活函数及其梯度

    import tensorflow as tf a = tf.linspace(-10., 10., 10) a with tf.GradientTape() as tape: tape.watch( ...

  3. 吴裕雄 python 神经网络——TensorFlow 花瓣分类与迁移学习(2)

    import glob import os.path import numpy as np import tensorflow as tf from tensorflow.python.platfor ...

  4. CentOS 7控制台屏幕分辨率问题

    我们在服务器上,很少会安装图形化界面,一般都使用字符界面的控制台.CentOS 下,控制台分辨率缺省情况下,变得很高,导致在显示器上花屏或者只能显示局部. 这是由于使用了frame buffer,好处 ...

  5. 关于OSPF LSA不稳定!

    Issue 1 Solution It is important that you understand the error message during attempts to troublesho ...

  6. 洛谷P1073最优贸易(跑两遍dij)

    题目描述 CC C国有n n n个大城市和m mm 条道路,每条道路连接这 nnn个城市中的某两个城市.任意两个城市之间最多只有一条道路直接相连.这 mmm 条道路中有一部分为单向通行的道路,一部分为 ...

  7. 杭电 2159 fate(二维背包费用问题)

    FATE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  8. 取消Oracle数据库密码期限 取消用户锁定

    1.首先查用户被锁时间:sql>select username,account_status,lock_date from dba_users where username='SA'; 2.解锁 ...

  9. vue 项目中的less

    收先要在cmd中运行 npm install less less-loader --save 然后会在 moudules文件夹中生成less 和less-loader <style lang=& ...

  10. mcast_set_if函数

    #include <errno.h> #include <string.h> #include <net/if.h> #include <sys/ioctl. ...