python使用ConfigParse解析配置文件
来源:互联网 发布:人人商城源码下载 编辑:程序博客网 时间:2024/05/16 17:32
1 my.cnf 样板数据
[client]port = 3306user = mysqlpassword = mysql[mysqld]basedir = /usrdatadir = /var/lib/mysqltmdir = /tmpskip-external-locking[mysql]host = 127.0.0.1
2 基本操作
#! /usr/bin/env python#coding:utf-8import ConfigParsercf=ConfigParser.ConfigParser(allow_no_value=True)cf.read('my.cnf')# ==========================读取==================================# 获取client,mysqld 段print(cf.sections())'''['client', 'mysqld']'''#判断client 是否存在print(cf.has_section('client'))'''True'''#将client内容以tuple返回print(cf.items('client'))'''[('prot', '3306'), ('user', 'mysql'), ('password', 'mysql'), ('host', '127.0.0.1')]'''# 返回client下的变量print(cf.options('client'))'''['port', 'user', 'password', 'host']'''#判断client下是否存在port变量print(cf.has_option('client','port'))'''True'''#获取client下的port值,其他方法:getboolean,getint,getfloatprint(cf.get('client','port'))'''3306'''#===========================增加或删除======================# 删除cf.remove_section('client')# cf.remove_option('client','port')# 添加cf.add_section("mysql")cf.set('mysql','host','127.0.0.1')#保存文件cf.write(open('my.cnf','w'))
阅读全文
0 0
- python使用ConfigParse解析配置文件
- python ConfigParse模块的使用
- 通过python的ConfigParse模块读写ini配置文件
- python3中的configparse配置文件
- python基础-hashlib、logging、configparse
- 【Python】配置文件解析模块ConfigParser使用实例
- python 使用ConfigParser解析&修改配置文件
- python 配置文件解析翻译
- python 解析配置文件
- [Python]ConfigParser解析配置文件
- python解析xml配置文件
- python解析配置文件
- python 解析properties配置文件.
- Python3.6安装ConfigParse(配置解析模块)安装
- 使用Python库ElementTree解析Hadoop的xml配置文件
- python 发送邮件 -- 解析配置文件
- 使用digester 解析xml配置文件
- 使用Digester解析XML配置文件
- 20171217
- IT领域——风投的宠儿
- 《软件测试的艺术(原书第2版)》【PDF】下载
- Spring Boot学习之旅创建第一个工程
- 清除节点上的gossip状态(二)
- python使用ConfigParse解析配置文件
- 详谈C++中虚基类在派生类中的内存布局
- 2017-12-17
- 工厂方法模式、抽象工厂模式、单例模式
- IT风投与中国
- 枚举、包装类、Math类、String类、Date类、Calendar类、Random类
- 在我的世界中实现了聊天框显示文字
- pyspark+jieba分词 数据标注(提取动词)
- fatal error: caffe/proto/caffe.pb.h: No such file or directory #include "caffe/proto/caffe.pb.h