作者girl5566 (5566520)
看板Python
标题[问题] 将list快速写入档案的方式?
时间Wed Mar 2 22:43:16 2016
f = open('123.txt','r')
lines = f.readlines()
print len(lines) #2000000 lines
startindex = 30
endindex = 15000
outputfile = open('456.txt','w')
for i in range(startindex,endindex):
outputfile.write(lines[i])
outputfile.close()
想询问除了这样写以外 有无更快的写法
可以直接把string list写到档案内的写法
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 123.195.222.114
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1456929799.A.310.html
1F:→ alibuda174: 不要用readlines;改用islice吧 03/02 23:36
2F:推 Yshuan: 可以用看看cStringIO, 概念像是pseudo file. 03/03 13:26