• ConfigParser模块


     

    用于生成和修改常见配置文档,当前模块的名称在 python 3.x 版本中变更为 configparser。

    来看一个好多软件的常见文档格式如下

    [DEFAULT]
    serveraliveinterval = 45
    compression = yes
    compressionlevel = 9
    forwardx11 = yes

    [bitbucket.org]
    user = hg

    [topsecret.server.com]
    host port = 50022
    forwardx11 = no

    #创建
    #!/usr/bin/env python

    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)

    #读写
    #!/usr/bin/env python
    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"))



  • 相关阅读:
    亚瑟阿伦36问
    Oracle动态SQL
    Oracle分页
    Oracle游标+动态SQL
    Oracle %type %rowtype
    Oracle游标
    Oracle存储过程和Java调用
    Oracle循环
    Oracle(if判断)
    Oracle视图
  • 原文地址:https://www.cnblogs.com/rongye/p/9942803.html
Copyright © 2020-2023  润新知