1. 程式人生 > >python 之 configparser 模塊

python 之 configparser 模塊

spa .py blog 模塊 ive .org span log serve

[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 之 configparser 模塊