txt文本文件写入
【1】txt文本文件写入,具体如下:
f1 = open('ysw.txt','w');
f1.write('halcom.cn')
f1.close();则在ysw.txt出现一个halcom.cn的字符串。
看过必回,人品超好! import os
txt_file = 'trainloss.txt'
try:
os.remove(txt_file)
except:
print('不存在改文件')
with open(txt_file,'a') as f:
f.write(str(1.01)+'\n')
f.write(str(10.5)+'\n')
f.write(str(5)+'\n')
f.write(str(6.2)+'\n')
f.close();
with open(txt_file,'a') as f:
f.write(str(1.01)+'\n')
f.write(str(10.5)+'\n')
f.write(str(5)+'\n')
f.write(str(6.2)+'\n')
f.close();
txt_file = 'trainloss.txt'
with open(txt_file, 'r') as f:
indexs1=f.readline()
indexs2=f.readlines()
index1 = float( indexs1 )
# print(index1)
index2 = str( indexs2 ).split('.')
页:
[1]