标签:pen host python bucket forward live war amp evel
import configparser
#write
‘‘‘
config = configparser.ConfigParser()
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 configfile:
config.write(configfile)
#read
config = configparser.ConfigParser()
config.read(‘example.ini‘)
print(config.sections())#取key
print(config[‘bitbucket.org‘][‘User‘])#取value值
‘‘‘
#增删改查语法
config = configparser.ConfigParser()
config.read(‘example.ini‘)
sec = config.remove_section(‘bitbucket.org‘)
config.write(open(‘i.cfg‘, "w"))#删除bitbucket.org并且创建一个新的文件
标签:pen host python bucket forward live war amp evel
原文地址:https://www.cnblogs.com/anhao-world/p/13138152.html