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'))
  • 相关阅读:
    python之路-javascript
    python之路-css
    python之路-初识前端
    python之路-线程
    python之路-socket
    base64 convert to file
    base64 json
    centos7 hostname
    geoip2 domain
    佛教六度
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8811066.html
Copyright © 2011-2022 走看看