標籤:secret import ret pos 模組 cat amp post top
[[email protected] python]# vim config.pyimport configparserconfig = 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‘))[[email protected] python]# python config.py[[email protected] python]# cat example.ini[DEFAULT]serveraliveinterval = 45compression = yescompressionlevel = 9forward = No[bitbucket.org]user = Root[topsecret.server.com]host port = 5200forward = yes[[email protected] python]# cat xml.ini[DEFAULT]serveraliveinterval = 45compression = yescompressionlevel = 9forward = No[bitbucket.org]user = Root
python 之 configparser 模組