zoukankan      html  css  js  c++  java
  • python之configparser模块

    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()
  • 相关阅读:
    缓冲式I/O
    事件轮询接口
    博弈游戏
    多任务I/O之poll函数
    好的link
    做纹理处理的。。。
    快毕业了!
    语音处理的资料
    google图像搜索原理
    install opencv in centos
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7580884.html
Copyright © 2011-2022 走看看