码迷,mamicode.com
首页 > 编程语言 > 详细

python之configparser模块

时间:2017-09-23 14:33:41      阅读:242      评论:0      收藏:0      [点我收藏+]

标签:模块   igp   for   int   pre   import   tin   port   with   

from configparser import ConfigParser


def write():
    cp = ConfigParser()
    cp[one] = {
        aa: 111,
        bb: 222
    }
    cp[two] = dict(
        cc=zxl,
        dd=hhu
    )
    cp[three] = {}
    cp[three][ee] = 888
    t = cp[three]
    t[ff] = 999
    with open(config, w) as f:
        cp.write(f)


def read():
    cp = ConfigParser()
    # print(cp.sections())
    result = cp.read(config)
    # print(cp.has_option(one, aa))
    # print(cp.has_section(three))
    # for i in cp:
    #     print(i)
    # for i in cp[two]:
    #     print(i)
    # print(type(result), result)
    # print(cp.sections())
    # print(one in cp)
    # print(cp[one])
    # value = cp[one][aa]
    # print(type(value), value)
    # value = cp.get(one, aa)
    # print(type(value), value)
    # value = cp.getint(one, aa)
    # print(type(value), value)


read()
def delete():
    cp = ConfigParser()
    read = cp.read(config)
    cp.remove_section(two)
    cp.remove_option(three, ee)
    with open(config2, w) as f:
        cp.write(f)


# delete()
def update():
    cp = ConfigParser()
    cp.read(config)
    cp.set(one, aa, zhangsan)
    with open(config, w) as f:
        cp.write(f)


# update()

 

python之configparser模块

标签:模块   igp   for   int   pre   import   tin   port   with   

原文地址:http://www.cnblogs.com/zhaoxianglong1987/p/7580884.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!