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'))
  • 相关阅读:
    打印机连接向导
    字符串替换
    登入脚本统一公司桌面
    判断文件是否存在
    DOS系统变量
    修改文件访问权限
    【CF1017C】The Phone Number(构造)
    【CF1017B】The Bits(模拟)
    【CF1017A】The Rank(签到)
    【CF1016B】Segment Occurrences(模拟)
  • 原文地址:https://www.cnblogs.com/lhqlhq/p/8811066.html
Copyright © 2011-2022 走看看