zoukankan      html  css  js  c++  java
  • python configparser模块常用操作

    import configparser
    #write
    '''
    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)

    #read
    config = configparser.ConfigParser()
    config.read('example.ini')
    print(config.sections())#取key
    print(config['bitbucket.org']['User'])#取value值
    '''
    #增删改查语法

    config = configparser.ConfigParser()
    config.read('example.ini')
    sec = config.remove_section('bitbucket.org')
    config.write(open('i.cfg', "w"))#删除bitbucket.org并且创建一个新的文件
  • 相关阅读:
    UVALive4727:jump
    UVALive
    UVA11795 Mega Man's Mission
    UVA4731:Cellular Network
    UVA11404:Palindromic Subsequence
    设计思路
    阅读计划
    上课未完成代码原因
    《人月神话》读后感
    《软件工程》第十一章总结
  • 原文地址:https://www.cnblogs.com/anhao-world/p/13138152.html
Copyright © 2011-2022 走看看