Halcom 发表于 2017-4-5 22:53:48

txt文本文件写入


【1】txt文本文件写入,具体如下:
f1 = open('ysw.txt','w');
f1.write('halcom.cn')
f1.close();则在ysw.txt出现一个halcom.cn的字符串。




cfbgsx 发表于 2017-8-8 20:48:29

看过必回,人品超好!

GTX_AI 发表于 2020-5-17 21:22:54

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]
查看完整版本: txt文本文件写入