def GetTrees(): ''' 获取根据属性生成所有树 :return: 返回所有属性的树,顺序在'attribute.txt'里面 ''' attribute = [] path = os.path.abspath('..') # 表示当前所处的文件夹上一级文件夹的绝对路径 path1 = path + "\data\\attribute.txt" infile = open(path1, 'r') attribute_file = infile.readline()[:-1] # 读取一行 attribute = (attribute_file.split(',')) trees = [] for i in range(len(attribute)): path2 = path + "\data//attribute_" + attribute[i] + '.txt' tree = a.Tree1() tree1 = tree.createTree(path2) trees.append(tree1) return trees
def GetTreesDict(): ''' 获取根据属性生成所有树 :return: 返回所有属性的树,顺序在'attribute.txt'里面 ''' treeDict ={} path = os.path.abspath('..') # 表示当前所处的文件夹上一级文件夹的绝对路径 path1 = path + "/data/attribute" infile = open(path1, 'r') attribute_file = infile.readline()[:-1] # 读取一行 attribute = (attribute_file.split(',')) trees = [] for i in range(len(attribute)): path2 = path + "/data/attribute_" + attribute[i] tree = a.Tree1() tree1 = tree.createTree(path2) treeDict[attribute[i]] = tree1 return treeDict