记录: Python解析yml文件,顺序解析,带所有文件等号from yaml.composer import Composer from yaml.constructor import Constructor import yamlclass ParseYml:def __init__(self):pass@staticmethoddef parse(yml_path=None):try:loader = yaml.Loader(open(yml_path))def compose_node(parent, index):line = loader.linenode = Composer.compose_node(loader, parent, index)node.__line__ = linereturn nodedef construct_mapping(node, deep=False):mapping = Constructor.construct_mapping(loader, node, deep=deep)mapping['__line__'] = node.__line__return mappingloader.compose_node = compose_nodeloader.construct_mapping = construct_mappingdata = loader.get_single_data()return dataexcept:raise "error"