配置文件截图如下:
提取主机和URL信息代码:
import yaml f = open('test.yml', encoding='utf-8') cfg = f.read() d = yaml.load(cfg, Loader=yaml.FullLoader) hostList=list(d['Server'].keys()) hostCount = len(hostList) for i in range(hostCount): Host = hostList[i] Url = d['Server'][Host][0]['Url'] print('Host' + Host ) print('Url:' + Url + ' ')
执行结果: