python ConfigParser 模块
ConfigParser的函数方法
读取配置文件
read(filename) 直接读取ini文件内容
sections() 得到所有的section,并以列表的形式返回
options(section) 得到该section的所有option
items(section) 得到该section的所有键值对
get(section,option) 得到section中option的值,返回为string类型
getint(section,option) 得到section中option的值,返回为int类型
写入配置文件
add_section(section) 添加一个新的section
set( section, option, value) 对section中的option进行设置
write将内容写入配置文件。
配置文件

代码
import ConfigParser
conf = ConfigParser.ConfigParser()
conf.read('test.conf') #读取配置文件 print conf.options('tornado')
print conf.sections() #以列表形式
print conf.get('tornado', 'port')
print conf.getint('tornado', 'port') #获取整数类型
conf.set('tornado', 'domain', '') #添加新的参数
conf.add_section("django") #添加新的模块
conf.set('django', 'port', 80) conf.write(open('test.conf', 'w'))#写入文件
python ConfigParser 模块的更多相关文章
- Python Configparser模块读取、写入配置文件
写代码中需要用到读取配置,最近在写python,记录一下. 如下,假设有这样的配置. [db] db_host=127.0.0.1 db_port=3306 db_user=root db_pass= ...
- python -ConfigParser模块讲解
configParser 模块用于操作配置文件 注:Parser汉译为“解析”之意. 配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键= ...
- python ConfigParser模块 配置文件解析
ConfigParser模块主要是用来解析配置文件的模块,像mysql,或者win下面的ini文件等等 下面我们来解析mysql的配置文件my.cnf my.cnf配置文件内容 [mysqld] da ...
- 【python】python configparser模块
ConfigParser模块在python中用来读取配置文件,配置文件的格式跟windows下的ini配置文件相似,可以包含一个或多个节(section), 每个节可以有多个参数(键=值).使用的配置 ...
- python configparser模块详解
此模块提供了一个实现基本配置语言的类 首先来看一个非常基本的配置文件,如下所示格式: [DEFAULT] ServerAliveInterval = 45 Compression = yes Comp ...
- Python - configParser模块学习
configParser 模块用于操作配置文件 注:Parser汉译为“解析”之意. 配置文件的格式与windows ini文件类似,可以包含一个或多个节(section),每个节可以有多个参数(键= ...
- python configparser模块
来看一个好多软件的常见文档格式如下: [DEFAULT] ServerAliveInterval = 45 Compression = yes CompressionLevel = 9 Forward ...
- Python configparser模块操作代码实例
1.生成配置文件 ''' 生成配置文件 很多人学习python,不知道从何学起.很多人学习python,掌握了基本语法过后,不知道在哪里寻找案例上手.很多已经做案例的人,却不知道如何去学习更加高深的知 ...
- python 常用模块之ConfigParser
在程序中使用配置文件来灵活的配置一些参数是一件很常见的事情,配置文件的解析并不复杂,在Python里更是如此,在官方发布的库中就包含有做这件事情的库,那就是ConfigParser, Python C ...
随机推荐
- [LeetCode] Best Time to Buy and Sell Stock 买卖股票的最佳时间
Say you have an array for which the ith element is the price of a given stock on day i. If you were ...
- C#网络编程——IPHostEntry
using System; using System.Net; namespace study { class IPHostEntrySample { public static void func( ...
- BAS/BRAS/RADIUS简介
标签: java radius协议 linux radius认证服务器 转自: http://blog.csdn.net/sun93732/article/details/5999274 由R ...
- 使用markdown
一.在windows下使用markdown MarkdownPad:MarkdownPad is a full-featured markdown editor for windows. Awsomi ...
- c#datagridview
//保证显示当前活动单元格 this.Invoke(new Action(() => { dataGridView1.CurrentCell = dataGridView1.Rows[index ...
- ROS中DDNS的使用
一.通过tool fetch更新ddns,关于此命令的使用,参考 tool fetch Scripts中添加脚本/tool fetch url="http://www.51kwl.com/? ...
- Beta版本冲刺总汇
DAY ONE: http://www.cnblogs.com/aruba/p/6149032.html posted @ 2016-12-09 12:37 DAY TWO: http://www.c ...
- Mysql 如何批量插入百万行测试数据
Mysql 如何批量插入百万行测试数据
- theano .dimshuffle
.dimshuffle 改变输入维度的顺序,返回原始变量的一个view. 输入是一个包含 $[0,1,...,ndim-1]$ 和任意数目的 $'x'$ 的组合: 例如: $('x')$:将标量变成 ...
- 自制-随机生成不重复的数组 --算法,egret平台下的TS code
感觉这个算法经常会用到,前段时间写过一次,现在push出来.原理是有两个数组,一个数组存放随机数,然后从另一个数组提取相关的数,然后把另一个数组的大小-1,remove掉这个数,unity里也是这个原 ...