Python学习记录W5-12:内置模块详解之Configparser模块——读取

xiaoxiao2021-02-28  21

[DEFAULT] serveraliveinterval = 45 compression = yes compressionlevel = 9 forwardx11 = yes [bitbucket.org] user = hg [topsecret.server.com] host port = 50022 forwardx11 = no

读取配置文件:

# Author: Allenlee import configparser conf = configparser.ConfigParser() conf.read("example.ini") print(conf.defaults()) #结果:OrderedDict([('serveraliveinterval', '45'), ('compression', 'yes'), ('compressionlevel', '9'), ('forwardx11', 'yes')]) print(conf.sections()) #结果:['bitbucket.org', 'topsecret.server.com'] print(conf['bitbucket.org']['user']) #结果:hg

转载请注明原文地址: https://www.6miu.com/read-2627256.html

最新回复(0)