码迷,mamicode.com
首页 > 编程语言 > 详细

python 之 configparser 模块

时间:2018-03-10 13:57:01      阅读:236      评论:0      收藏:0      [点我收藏+]

标签:secret   import   ret   pos   模块   cat   amp   post   top   

[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 模块

标签:secret   import   ret   pos   模块   cat   amp   post   top   

原文地址:https://www.cnblogs.com/lixinliang/p/8538607.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!