python 之 configparser 模块

Posted lixinliang

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 之 configparser 模块相关的知识,希望对你有一定的参考价值。

[[email protected] 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))

[[email protected] python]# python config.py


[[email protected] 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

[[email protected] python]# cat xml.ini
[DEFAULT]
serveraliveinterval = 45
compression = yes
compressionlevel = 9
forward = No

[bitbucket.org]
user = Root

 

以上是关于python 之 configparser 模块的主要内容,如果未能解决你的问题,请参考以下文章

python 之configparser模块

python 之 configparser 模块

python常用模块之configparser模块

python常用模块之configparser模块

Python学习---重点模块之configparse

python模块之configparser_logging_re