def get_cor():
x = [] # 第几张图
y = [] # dice系数是多少
with open("results.txt", "r", encoding="utf-8") as f:
for line in f: # 遍历每一行
number = re.findall(r'\d+(?:\.\d+)?', line)
x.append(int(number[0]))
y.append(float(number[1]))
f.close()
return x, y
results.txt
是文本的名字,可以改成文件的名字encoding="utf-8"
是为了解决文本出现中文的办法re.findall(r'\d+(?:\.\d+)?', line)
匹配正则式