看板 [ Python ]
討論串[問題] 將list快速寫入檔案的方式?
共 3 篇文章
首頁
上一頁
1
下一頁
尾頁

推噓2(2推 0噓 5→)留言7則,0人參與, 最新作者stimim (qqaa)時間9年前 (2016/03/08 11:54), 編輯資訊
0
1
0
內容預覽:
因為不用把整個檔案讀進記憶體,在檔案大的時候肯定會比 readlines() 快不少. 另外,我發現如果用 itertools + writelines 的話,可以再快一些. 實驗方法:. 1. 生成檔案:. n = 2 * 10 ** 7. for _ in xrange(n):. print _
(還有571個字)

推噓2(2推 0噓 0→)留言2則,0人參與, 最新作者uranusjr (←這人是超級笨蛋)時間9年前 (2016/03/02 23:35), 9年前編輯資訊
0
0
1
內容預覽:
如果你有仔細看文件, 應該會發現裡面有個 writelines method.... https://docs.python.org/2/library/stdtypes.html#file.writelines. startindex = 30. endindex = 15000. with op
(還有360個字)

推噓1(1推 0噓 1→)留言2則,0人參與, 最新作者girl5566 (5566520)時間9年前 (2016/03/02 22:43), 編輯資訊
0
0
0
內容預覽:
f = open('123.txt','r'). lines = f.readlines(). print len(lines) #2000000 lines. startindex = 30. endindex = 15000. outputfile = open('456.txt','w').
(還有91個字)
首頁
上一頁
1
下一頁
尾頁