请选择 进入手机版 | 继续访问电脑版

Hello Mat

 找回密码
 立即注册
查看: 6032|回复: 2

txt文本文件写入

[复制链接]

1288

主题

1514

帖子

90

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
22589
发表于 2017-4-5 22:53:48 | 显示全部楼层 |阅读模式

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




算法QQ  3283892722
群智能算法链接http://halcom.cn/forum.php?mod=forumdisplay&fid=73
回复

使用道具 举报

0

主题

3

帖子

9

金钱

新手上路

Rank: 1

积分
12
发表于 2017-8-8 20:48:29 | 显示全部楼层
看过必回,人品超好!
回复 支持 反对

使用道具 举报

84

主题

115

帖子

731

金钱

管理员

Rank: 9Rank: 9Rank: 9

积分
1467
发表于 2020-5-17 21:22:54 | 显示全部楼层
  1. import os
  2. txt_file = 'trainloss.txt'
  3. try:
  4.     os.remove(txt_file)
  5. except:
  6.     print('不存在改文件')
  7. with open(txt_file,'a') as f:
  8.     f.write(str(1.01)+'\n')
  9.     f.write(str(10.5)+'\n')
  10.     f.write(str(5)+'\n')
  11.     f.write(str(6.2)+'\n')
  12. f.close();
  13. with open(txt_file,'a') as f:
  14.     f.write(str(1.01)+'\n')
  15.     f.write(str(10.5)+'\n')
  16.     f.write(str(5)+'\n')
  17.     f.write(str(6.2)+'\n')
  18. f.close();


  19. txt_file = 'trainloss.txt'
  20. with open(txt_file, 'r') as f:
  21.     indexs1=f.readline()
  22.     indexs2=f.readlines()
  23.     index1 = float( indexs1 )
  24. #    print(index1)
  25.     index2 = str( indexs2 ).split('.')[0]
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Python|Opencv|MATLAB|Halcom.cn ( 蜀ICP备16027072号 )

GMT+8, 2024-3-29 16:18 , Processed in 0.228340 second(s), 24 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表