zoukankan      html  css  js  c++  java
  • day05_03 configparser 生成模块文件

    __author__ = "Alex Li"
    
    import configparser #ConfigParser
    
    config = configparser.ConfigParser()
    
    config["DEFAULT"] = {'ServerAliveInterval': '45',
                         'Compression': 'yes',
                         'CompressionLevel': '9'}
    
    config['bitbucket.org'] = {}
    config['bitbucket.org']['User'] = 'hg'
    
    config['topsecret.server.com'] = {}
    config['topsecret.server.com']
    config['topsecret.server.com']['Host Port'] = '50022'  # mutates the parser
    config['topsecret.server.com']['ForwardX11'] = 'no'  # same here
    
    config['DEFAULT']['ForwardX11'] = 'yes'
    
    
    with open('example.ini', 'w') as configfile:
        config.write(configfile)
    

    生成文件效果

    __author__ = "Alex Li"
    
    import configparser #ConfigParser
    
    config = configparser.ConfigParser()
    
    config["DEFAULT"] = {'ServerAliveInterval': '45',
                         'Compression': 'yes',
                         'CompressionLevel': '9'}
    
    config['bitbucket.org'] = {}
    config['bitbucket.org']['User'] = 'hg'
    
    config['topsecret.server.com'] = {}
    config['topsecret.server.com']
    config['topsecret.server.com']['Host Port'] = '50022'  # mutates the parser
    config['topsecret.server.com']['ForwardX11'] = 'no'  # same here
    
    config['DEFAULT']['ForwardX11'] = 'yes'
    
    
    with open('example.ini', 'w') as configfile:
        config.write(configfile)
    

    configparser读

    __author__ = "Alex Li"
    
    import configparser
    
    conf = configparser.ConfigParser()
    conf.read("example.ini")
    
    print(conf.defaults())
    print(conf['bitbucket.org']['user'])
    #print(conf.sections())
    
    # 删除源文件内容
    sec = conf.remove_section('bitbucket.org')
    conf.write(open('example.ini', "w"))
    
  • 相关阅读:
    asp.net AD 域验证
    ASP.NET身份验证
    .Net默认IE版本号的两种方式
    (转)移动端自适应方案
    (转)手机web——自适应网页设计(html/css控制)
    (转)优雅降级和渐进增强的区别
    (转)hasLayout与BFC的触发条件
    (转)js中几种实用的跨域方法原理详解
    (转)js实现继承的5种方式
    (转)js 判断各种数据类型
  • 原文地址:https://www.cnblogs.com/netflix/p/14855050.html
Copyright © 2011-2022 走看看