zoukankan      html  css  js  c++  java
  • 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'))
  • 相关阅读:
    二维几何前置知识
    点分治学习笔记
    $fhq-treap$学习笔记
    对拍使用方法
    2021.2.18-2021.5.18 三个月后端开发实习的学习路径
    蓝桥杯常考算法 + 知识点
    Linux
    Linux
    Intern Day112
    Linux上编译运行C/C++程序
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8811066.html
Copyright © 2011-2022 走看看