谁知道python模块:configparser模块

2020年10月18日 星期日 seo网站关键词优化

 

标签:openefaultrettoppreportESSwith openbit

常见文档的格式如下:

[DEFAULT]
ServerAliveInterval = 45
Compression = yes
CompressionLevel = 9
ForwardX11 = yes
  
[bitbucket.org]
User = hg
  
[topsecret.server.com]
Port = 50022
ForwardX11 = no

用python生成这样的文档如下:

import configparser

config = configparser.ConfigParser()

config["DEFAULT"] = {‘ServerAliveInterval‘: ‘45‘,
                      ‘Compression‘: ‘yes‘,
                     ‘CompressionLevel‘: ‘9‘,
                     ‘ForwardX11‘:‘yes‘
                     }

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

config[‘topsecret.server.com‘] = {‘Host Port‘:‘50022‘,‘ForwardX11‘:‘no‘}

with open(‘example.ini‘, ‘w‘) as configfile:

   config.write(configfile)

  

python模块:configparser模块

标签:openefaultrettoppreportESSwith openbit

原文地址:https://www.cnblogs.com/wuchangblog/p/13813784.html

您可能也喜欢