标签:.config 添加节点 options print 获取 result import oat eric
[kaixin]
xxx = 333
name = hah
heh = 0
[erick]
age = 123555
xxx = ooo555
name = hah555
1 import configparser 2 3 con = configparser.ConfigParser() 4 con.read("ini",encoding=‘utf-8‘) 5 # 所有节点 6 result = con.sections() 7 #print(result) 8 # 所有键 9 ret = con.options(‘kaixin‘) 10 #print(ret) 11 # 所有键值对 12 items = con.items(‘kaixin‘) 13 #print(items) 14 # 获取节点下指定键的值 15 # v= con.get(‘kaixin‘,‘age‘) 16 # k =con.getint(‘kaixin‘,‘age‘) 17 # r =con.getfloat(‘kaixin‘,‘age‘) 18 # b = con.getboolean(‘kaixin‘,‘heh‘) 19 # #print(v,k,r,b) 20 #检查是否存在节点 21 has_sec = con.has_section(‘kaixin‘) 22 #print(has_sec) 23 # 添加节点 24 # con.add_section(‘SET1‘) 25 # con.write(open(‘ini‘,‘w‘)) 26 # 删除节点 27 # con.remove_section(‘SET1‘) 28 # con.write(open(‘ini‘,‘w‘)) 29 # 检查是否存在相应的键 30 # has_opt = con.has_option(‘kaixin‘,‘age‘) 31 #print(has_opt) 32 # 删除键值对 33 # con.remove_option(‘kaixin‘,‘age‘) 34 # con.write(open(‘ini‘,‘w‘)) 35 36 #设置键值对 37 con.set(‘kaixin‘,‘xxx‘,‘333‘) 38 con.write(open(‘ini‘,‘w‘))
标签:.config 添加节点 options print 获取 result import oat eric
原文地址:http://www.cnblogs.com/Erick-L/p/6418081.html