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)
相关推荐
YENCSDN 2020-11-17
lsjweiyi 2020-11-17
houmenghu 2020-11-17
Erick 2020-11-17
HeyShHeyou 2020-11-17
以梦为马不负韶华 2020-10-20
lhtzbj 2020-11-17
夜斗不是神 2020-11-17
pythonjw 2020-11-17
dingwun 2020-11-16
lhxxhl 2020-11-16
坚持是一种品质 2020-11-16
染血白衣 2020-11-16
huavhuahua 2020-11-20
meylovezn 2020-11-20
逍遥友 2020-11-20
weiiron 2020-11-16