zoukankan      html  css  js  c++  java
  • 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"))



  • 相关阅读:
    go并发和并行
    goroutine
    go并发
    wampserver配置问题
    获取字符串的长度
    mysql中事件失效如何解决
    Go语言中Goroutine与线程的区别
    Mosquitto服务器的日志分析
    phpexcel导出数据 出现Formula Error的解决方案
    Centos6.X 手动升级gcc
  • 原文地址:https://www.cnblogs.com/rongye/p/9942803.html
Copyright © 2011-2022 走看看