#配置文件模块 import configparser config = configparser.ConfigParser() config['default'] = { 'ServerAliveInterval': '45', 'Conpression': 'yes', 'ConpressionLevel': '9' } config['bitbucket.org'] = { 'User': 'hg' } config['topscret.server.com'] = {} topscret = config['topscret.server.com'] topscret['Host Port'] = '5001' topscret['forwardX11'] = 'no' config['default']['forwarX11'] = 'yes' with open('example.ini', 'w') as configfile: config.write(configfile) ================================================================================================#配置文件模块 import configparser config = configparser.ConfigParser() config.read('example.ini') print(config.sections()) #['default', 'bitbucket.org', 'topscret.server.com'] print(config['default']['Conpression']) for key in config['default']: print(key)================================================================================================#配置文件模块 import configparser config = configparser.ConfigParser() config.read('example.ini') #***先读取 print(config.has_section('default')) config.set('bitbucket.org', 'user', 'leo')config.remove_option('bitbucket.org', 'user')config.write(open('example.ini', 'w')) #***重写
python中configParser模块的基础用法
最新推荐文章于 2022-11-03 11:14:00 发布