zoukankan      html  css  js  c++  java
  • python 之 configparser 模块

    [root@linag python]# vim config.py
    
    import configparser
    
    config = configparser.ConfigParser()
    config["DEFAULT"] = {'ServerAliveInterval': '45',
                         'Compression': 'yes',
                         'CompressionLevel': '9'}
    config['bitbucket.org'] = {}
    config['bitbucket.org']['User'] = 'Root'
    
    config['topsecret.server.com'] = {}
    topsecret = config['topsecret.server.com']
    topsecret['Host Port'] = '5200'
    topsecret['Forward'] = 'yes'
    
    config['DEFAULT']['Forward'] = 'No'
    
    with open('example.ini','w') as configfile:
      config.write(configfile)
    
    config.set('topsecret.server.com','Hosr Port','5601')  #
    
    config.remove_section('topsecret.server.com') #
    config.write(open ('xml.ini','w'))
    
    [root@linag python]# python config.py
    
    
    [root@linag python]# cat example.ini
    [DEFAULT]
    serveraliveinterval = 45
    compression = yes
    compressionlevel = 9
    forward = No
    
    [bitbucket.org]
    user = Root
    
    [topsecret.server.com]
    host port = 5200
    forward = yes
    
    [root@linag python]# cat xml.ini
    [DEFAULT]
    serveraliveinterval = 45
    compression = yes
    compressionlevel = 9
    forward = No
    
    [bitbucket.org]
    user = Root
  • 相关阅读:
    Python是如何进行内存管理的?
    scrapy利用set()对数据进行去重
    python快速抓取新闻标题及内容
    python爬虫第三方库
    Spring使用@Scheduled定时调度
    redis启动失败
    视图系统
    路由系统
    Django框架 part 2
    Django框架
  • 原文地址:https://www.cnblogs.com/lixinliang/p/8538607.html
Copyright © 2011-2022 走看看