Tracy's Studio.

python提取记事本文件中的数字绘制数字变化曲线

字数统计: 70阅读时长: 1 min
2021/06/07 Share

python读取记事本文件

1
2
3
4
5
6
7
8
9
filename = "D:\\OneDrive\\code\\aba\\output\\alarm\\v5\\sample10000_gen500_pop100_K2_0\\info.txt"
f = open(filename, encoding='utf-8')
...: while True:
...: line = f.readline()
...: if line:
...: print (line)
...: else:
...: break
...: f.close()

正则表达式

1
2
3
4
string = "gen 70: best score: -106886.61585569178, min sparsity: , true score: -106445.6497111178"
all_score = re.findall(r"-\d+\.?\d*",string)
x_gen = float(all_score[0])
true_score = float(all_score[1])
CATALOG
  1. 1. python读取记事本文件
  2. 2. 正则表达式