码迷,mamicode.com
首页 > 其他好文 > 详细

import configparser 通过 .py写.ini文件

时间:2019-12-22 16:43:09      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:span   sam   top   example   igp   val   HERE   parse   parser   

import configparser

config = configparser.ConfigParser()
# config = {}
config["DEFAULT"] = {‘ServerAliveInterval‘: ‘45‘,
                     ‘Compression‘: ‘yes‘,
                     ‘CompressionLevel‘: ‘9‘}

config[‘bitbucket.org‘] = {}
config[‘bitbucket.org‘][‘User‘] = ‘hg‘

config[‘topsecret.server.com‘] = {}
topsecret = config[‘topsecret.server.com‘]
topsecret[‘Host Port‘] = ‘50022‘  # mutates the parser
topsecret[‘ForwardX11‘] = ‘no‘  # same here

config[‘DEFAULT‘][‘ForwardX11‘] = ‘yes‘
with open(‘example.ini‘, ‘w‘) as f:
    config.write(f)

import configparser 通过 .py写.ini文件

标签:span   sam   top   example   igp   val   HERE   parse   parser   

原文地址:https://www.cnblogs.com/hb15988111121/p/12080002.html

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