看板
[ Python ]
討論串[問題] 將list快速寫入檔案的方式?
共 3 篇文章
首頁
上一頁
1
下一頁
尾頁
內容預覽:
因為不用把整個檔案讀進記憶體,在檔案大的時候肯定會比 readlines() 快不少. 另外,我發現如果用 itertools + writelines 的話,可以再快一些. 實驗方法:. 1. 生成檔案:. n = 2 * 10 ** 7. for _ in xrange(n):. print _
(還有571個字)
內容預覽:
如果你有仔細看文件, 應該會發現裡面有個 writelines method.... https://docs.python.org/2/library/stdtypes.html#file.writelines. startindex = 30. endindex = 15000. with op
(還有360個字)
內容預覽:
f = open('123.txt','r'). lines = f.readlines(). print len(lines) #2000000 lines. startindex = 30. endindex = 15000. outputfile = open('456.txt','w').
(還有91個字)
首頁
上一頁
1
下一頁
尾頁