python3 configparser模块
配置文件如下:

import configparser conf = configparser.ConfigParser()
print(type(conf)) #conf是类
conf.read('config.ini')
sections = conf.sections() #获取配置文件中所有sections,sections是列表
print(sections)
option = conf.options(conf.sections()[0]) #获取某个section下的所有选项或value,等价于 option = conf.options('logoninfo')
print(option)
#value = conf.get('logoninfo', 'addr') #根据section和value获取key值,等价于value = conf.get(conf.sections()[0], conf.options(conf.sections()[0])[0])
print(value)
item = conf.items('logoninfo')
print(item) 运行结果如下:
<class 'configparser.ConfigParser'>
['logoninfo', 'logging', 'mysql']
['addr', 'passwd', 'popserver']
wangershazi
[('addr', 'wangershazi'), ('passwd', 'wangerxifu'), ('popserver', 'newmail')]
Process finished with exit code 0
python3 configparser模块的更多相关文章
- Python3.x:ConfigParser模块的使用
Python3.x:ConfigParser模块的使用 简介 ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节 ...
- Python3 logging模块&ConfigParser模块
''' 博客园 Infi_chu ''' ''' logging模块 该模块是关于日志相关操作的模块 ''' import logging # logging.debug('debug') # log ...
- (15)-Python3之--configparser模块
1.模块简介 configparser模块是python用来读取配置文件的模块,置文件的格式跟windows下的ini或conf配置文件相似,可以包含一个或多个节(section), 每个节可以有多个 ...
- Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 一.前言 我们在<中我们描述了Python数据持久化的大体概念和基本处理方式,通过这些知识点我们已经 ...
- 【转】Python3 configparse模块(配置)
[转]Python3 configparse模块(配置) ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(s ...
- Python3 configparse模块(配置)
ConfigParser模块在python中是用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section),每个节可以有多个参数(键=值). 注意:在 ...
- 【转】Python之xml文档及配置文件处理(ElementTree模块、ConfigParser模块)
[转]Python之xml文档及配置文件处理(ElementTree模块.ConfigParser模块) 本节内容 前言 XML处理模块 ConfigParser/configparser模块 总结 ...
- (转)python的ConfigParser模块
原文:https://blog.csdn.net/miner_k/article/details/77857292 如何使用Python3读写INI配置文件-------https://blog.cs ...
- Python - configParser模块学习
configParser 模块用于操作配置文件 注:Parser汉译为“解析”之意. 配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键= ...
随机推荐
- PHP curl拓展的介绍和使用
curl_setopt($ch, CURLOPT_URL, 'http://www.baidu.com/');//请求url地址curl_setopt($ch, CURLOPT_HEADER, 0); ...
- layoutSubviews何时调用的问题(原文:http://www.cnblogs.com/pengyingh/articles/2417211.html)
今天跟旺才兄学习了一下UIView的setNeedsDisplay和setNeedsLayout方法.首先两个方法都是异步执行的.而setNeedsDisplay会调用自动调用drawRect方法,这 ...
- netdevice - 底层访问 Linux 网络设备
总览 (SYNOPSIS) #include <sys/ioctl.h> #include <net/if.h> 描述 (DESCRIPTION) 本手册 描述 用于 配置 网 ...
- VB Open 函数详解 打开、关闭、读、写文件
(一)打开和关闭文件 1.顺序文件 打开顺序文件,我们可以使用Open语句.它的格式如下:Open pathname For [Input |Output |Append] As [ ...
- Oracle 9i,10g,11g各自alert日志的位置
10g&9i的alert日志: 进入oracle:[zhangshengdong@oralocal1 ~]$ sudo su - oracle[oracle@oralocal1 ~]$ sql ...
- 关于在IOS中 contenteditable=true 无法输入的问题
解决: 1.添加样式-webkit-user-select:text 2.如果引入了fastclick,需要添加个类名 needsclick 来源于知乎(https://www.zhihu.com/q ...
- 【03】Python 文件读写 JSON
1 打开文件 文件操作步骤: 1.打开文件获取文件的句柄,句柄就理解为这个文件 2.通过文件句柄操作文件 3.关闭文件. 1.1 打开方法 f = open('xxx.txt') #需f.close( ...
- 运算符、流程控制(if、while)笔记
目录 算术运算符 比较运算符(返回一个bool值) 逻辑运算符(把多个条件同时叠加) 赋值运算符 身份运算符 位运算符 成员运算符 python运算优先级 流程控制:向一个方向变化 if判断 单分支结 ...
- B1016. 部分 A+B
题目描述 正整数A的"D(为1位整数)部分"定义由A中所有D组成的新整数P,例如给定A=3862767,D=6,则A的"6部分" P是66,因为A中有2个6,现 ...
- 【SaltStack官方版】—— states教程, part 2 - 更复杂的states和必要的事物
states tutorial, part 2 - more complex states, requisites 本教程建立在第1部分涵盖的主题上.建议您从此处开始. 在Salt States教程的 ...