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()
  • 相关阅读:
    Antenna Placement poj 3020
    Asteroids
    深入了解IOC
    Java读取.properties配置文件
    java使用插件pagehelper在mybatis中实现分页查询
    javaweb分页查询实现
    java生成UUID
    java验证码的制作和验证
    java调用天气预报接口案例
    Maven入门
  • 原文地址:https://www.cnblogs.com/zhaoxianglong1987/p/7580884.html
Copyright © 2011-2022 走看看