import os import glob import re import pandas if __name__ == "__main__": bleu_files = glob.glob('./scores/model.iter*.npz.bleu') lines = [] for bleu_file in bleu_files: lines += [[os.path.abspath(bleu_file), float(re.sub(r'.*?=\s*([^,]+).*', '\\1', line.rstrip('\n')))] for line in open(bleu_file)] df = pandas.DataFrame(lines, columns=list('AB')) print(df['A'].loc[df['B'].idxmax()])