import glob import os scores_files = glob.glob('./scores/model.iter*[0-9].npz.bleu') max_result = { 'path': '', 'score': 0.0 } for f in scores_files: read_file = open(f, 'r').read().split() result = float(read_file[2][:-1]) if(result > max_result['score']): max_result['score'] = result max_result['path'] = f print(os.path.abspath(max_result['path']))