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"))



  • 相关阅读:
    Python多线程join的用法
    Python多线程互斥锁
    python Queue模块
    精度计算————乘法(大数乘小数)
    精度计算——大数阶乘
    python埃式筛法求素数
    Scala io操作
    scala io,ubuntu常见配置
    大数据之scala高级语法学习
    大数据之scala基本语法学习
  • 原文地址:https://www.cnblogs.com/rongye/p/9942803.html
Copyright © 2011-2022 走看看