首页 > 编程语言 > 详细

Python读写大文件-将整行文字根据分号分行

时间:2020-04-28 17:44:23      阅读:93      评论:0      收藏:0      [点我收藏+]
f = open("DDD_sales.txt", r, True)
filepath="data1.txt"
f1 = open(filepath, mode="a", encoding="utf-8")
line=""
ix=0
while True:
  # 每次读取一个字符
  ch = f.read(1)
  # 如果没有读到数据,跳出循环
  if not ch: break
  line= line+str(ch)
  if(ch==";"):
      ix=ix+1
      f1.write(str(line[0:len(line) - 1])+ "\n")
      f1.flush()
      print(str(ix))
      line=""
f1.close()
f.close()

 

Python读写大文件-将整行文字根据分号分行

原文:https://www.cnblogs.com/want990/p/12795579.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!