• configparser 模块


    import configparser

    config = configparser.ConfigParser() #相当于有一个空字典config

    import configparser

    config = configparser.ConfigParser()
    config["DEFAULT"] = {'ServerAliveInterval': '45',
    'Compression': 'yes',
    'CompressionLevel': '9'}

    config['bitbucket.org'] = {}
    config['bitbucket.org']['User'] = 'hg'
    config['topsecret.server.com'] = {}
    topsecret = config['topsecret.server.com']
    topsecret['Host Port'] = '50022' # mutates the parser
    topsecret['ForwardX11'] = 'no' # same here
    config['DEFAULT']['ForwardX11'] = 'yes'
    with open('example.ini', 'w') as configfile:
    config.write(configfile)
    #--------------------------------------增删改查
    import configparser

    config = configparser.ConfigParser()

    # -------------- 查
    config.read('example.ini') #读取文件
    # print(config.sections()) #打印除defult以外的块名
    # print(config['bitbucket.org']['user'])
    # for key in config['bitbucket.org']:
    # print(key)


    #---增删改
    # config.add_section('doudou') #增加块
    # config.set('doudou','gou','12') #对doudou块里面增加一个gou键,其对应的值是12

    config.remove_section('doudou') #删除块
    config.remove_option('bitbucket.org','user')


    config.write(open('new_example.ini','w'))
  • 相关阅读:
    STUN协议简介
    AssetManager asset使用
    采购申请 POCIRM-001:ORA-01403: 无论数据未找到
    Windows7在自由的虚拟机(微软官方虚拟机)
    C面试题
    热血江湖按键精灵脚本游戏!
    System.setProperty()
    Linux下patch打补丁命令
    Eclipse和PyDev搭建python开发环境
    二维数组中的查找
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8811066.html
Copyright © 2020-2023  润新知