网络编程
位置:首页>> 网络编程>> Python编程>> python实现读取大文件并逐行写入另外一个文件

python实现读取大文件并逐行写入另外一个文件

作者:UPBETTER  发布时间:2021-02-03 21:10:45 

标签:python,逐行,写入,文件

<pre name="code" class="python">creazy.txt文件有4G,逐行读取其内容并写入monday.txt文件里。

def creazyRead():
 '''''
 with open("e:creazy.txt","r") as cr:
   for line in cr:
     print line
 '''
 ms = open("e:creazy.txt")
 for line in ms:
   with open("e:monday.txt","a") as mon:
     mon.write(line)

另一种方法使用readlines实现:


def creazyRead():
 ms = open("e:creazy.txt")
 for line in ms.readlines():
   with open("e:monday.txt","a") as mon:
     mon.write(line)

来源:https://blog.csdn.net/DXLDeHuaLi/article/details/51350713

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com