configparser 莫模块

# /usr/bin/env python
# ! -*- encoding=utf-8 -*-

#导入模块
import configparser

#创建configparser对象
conn = configparser.ConfigParser()
# 读取配置文件 read()
conn.read('conf',encoding='utf-8')
#读取所有节点
#node = conn.sections()

#检测指定的节是否存在,返回时为true为真,为则false
#node = conn.has_section('test1')

#读取返回指定的项 options()
#node = conn.options('test1')

#判断指定的项的键是否存在
#node = conn.has_option('test1','name')

#获取指定节的指定键的值
#node = conn.get('test1','name')

#设置指定键的值
#conn.set('test1','name',"'jeans'")
#conn.write(open('conf','w'))

#增加节点 add_section()
#conn.add_section('test3')
#conn.set('test3','name','java')
#conn.set('test3','age','1')
#conn.write(open('conf','a'))

#删除节点 remove_section()
#conn.remove_section('test1')
#conn.write(open('conf','w'))

#删除节点键
#conn.remove_option('test2','age')
#conn.write(open('conf','w'))

原文地址:https://www.cnblogs.com/zxcv-/p/7732089.html