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 ...
随机推荐
- 关于umask的计算方式(简单任性)
1.对于文件夹[d]来说 用755-umask 3.对与文件[f]来说,在2的基础上减掉x属性就完事儿(有x的,减掉1,没有的,就什么也不管) 再来个手绘版本的举例
- leetcode菜鸡斗智斗勇系列(9)--- Range Sum of BST
1.原题: https://leetcode.com/problems/range-sum-of-bst/ Given the root node of a binary search tree, r ...
- vscode安装过的插件
1.VSCode的Vue插件Vetur设置,alt+shift+f格式化 对应配置 今天看到的文章安装插件可以参考: https://blog.csdn.net/maixiaochai/article ...
- vue 中 限制 input 输入数字、小数位数等
限制小数位数 <input type="number" @keydown="handleInput2" placeholder="请输入或查看& ...
- juypter
juypter 1. jupyter 1.1. 它是什么? Jupyter Notebooks 是一款开源的网络应用,我们可以将其用于创建和共享代码与文档. 以前叫ipython no ...
- 怪异盒子模型和行内元素的float
设置了float属性的行内元素的display值会变成inline-block 怪异盒子模型: box-sizing:border-box:元素content包含内间距和border
- 关于找不到指定的模块,异常来自HRESULT:0x8007007E的解决方法
上午从公司前辈那里拷贝到的ASP.NET代码,在自己机器上部署的时候发现问题,直接报错,找不到指定的模块,异常来自HRESULT:0x8007007E.并且一大堆警告. 在网上百度很多解决方法,归纳如 ...
- centos610无桌面安装libreoffice缺失字体
1.安装libreoffice 2.安装fontconfig yum -y install fontconfig 3.安装ttmkfdir yum -y install ttmkfdir 4.检查已有 ...
- SpringBoot yml文件语法
SpringBoot提供了大量的默认配置,如果要修改默认配置,需要在配置文件中修改. SpringBoot默认会加载resource下的配置文件: application*.yml applicati ...
- RuntimeError: cuda runtime error (10) : invalid device ordinal
This is caused by the unmatching of gpu device number when loading a saved model. torch.load('my_fil ...