import re; def main(): file = open("anova_rf-0.txt", "r") val_acc_rgx = re.compile("val_acc:\s\d\.\d{4}") for line in file.readlines(): m = val_acc_rgx.search(line) if m: print(float(m.group(0).split(" ")[1])) if __name__ == "__main__": main()