configparser 练习


[kaixin]
xxx = 333
name = hah
heh = 0 [erick]
age = 123555
xxx = ooo555
name = hah555

 1 import configparser

 con = configparser.ConfigParser()
con.read("ini",encoding='utf-8')
# 所有节点
result = con.sections()
#print(result)
# 所有键
ret = con.options('kaixin')
#print(ret)
# 所有键值对
items = con.items('kaixin')
#print(items)
# 获取节点下指定键的值
# v= con.get('kaixin','age')
# k =con.getint('kaixin','age')
# r =con.getfloat('kaixin','age')
# b = con.getboolean('kaixin','heh')
# #print(v,k,r,b)
#检查是否存在节点
has_sec = con.has_section('kaixin')
#print(has_sec)
# 添加节点
# con.add_section('SET1')
# con.write(open('ini','w'))
# 删除节点
# con.remove_section('SET1')
# con.write(open('ini','w'))
# 检查是否存在相应的键
# has_opt = con.has_option('kaixin','age')
#print(has_opt)
# 删除键值对
# con.remove_option('kaixin','age')
# con.write(open('ini','w')) #设置键值对
con.set('kaixin','xxx','')
con.write(open('ini','w'))
上一篇:工作流activiti-02事物控制、流程引擎创建


下一篇:读书笔记之 - javascript 设计模式 - 观察者模式