python使用yaml模块读取json配置文件

test.yaml

172.25.16.231:
  basecdnid: 0
  nfsid: 0
172.25.16.30:
  basecdnid: 4
  nfsid: 13
172.25.16.32:
  basecdnid: 1
  nfsid: 11
172.25.16.33:
  basecdnid: 1
  nfsid: 12
172.25.16.34:
  basecdnid: 1
  nfsid: 13
172.25.16.37:
  basecdnid: 4
  nfsid: 15
172.25.16.38:
  basecdnid: 4
  nfsid: 9
172.25.16.40:
  basecdnid: 4
  nfsid: 16
import yaml

file='test.yaml'
vipfile = 'double_domain.txt'

def get_dict(file):
    with open(file,'r') as file_object:
        cfg = file_object.read()
        ip_dict = yaml.load(cfg,Loader=yaml.FullLoader)
    return ip_dict

你可能感兴趣的:(python,yaml,python)