Ps:基于 Python3 创建配置文件 在项目根目录下创建 .ini 格式的配置文件: touch conf.ini 配置文件大概长这样: [DEFAULT]ServerAliveInterval = 45Compression = yesCompressionLevel = 9ForwardX11 = yes[bitbucket.org]User = hg[debug]log_errors=trueshow_warnings=False[topsecret.server.com]Port = 50022ForwardX11 = no 优雅读取 from configparserconfig = configparser.ConfigParser()config.read("./conf.ini")config.sections()# 读取配置config.get("DEFAULT", "Compression")cfg.getboolean('debug','log_errors')config.getint("topsecret.server.com", "Port") 参考资料 configparser — Configuration file parser 读取配置文件 赞微海报分享
近期评论