+ 10

How to read line by line from 4GB txt file with out loading the whole file to RAM??

in python

1st Feb 2018, 6:06 PM
^_^
^_^ - avatar
7 Respuestas
+ 7
I mean how can I read more than 600 line with out memory load or error
1st Feb 2018, 6:55 PM
^_^
^_^ - avatar
+ 7
i need to make my code to keep the whole file itself rather to read a line in a time, process it then reads the second line and so on
1st Feb 2018, 7:56 PM
^_^
^_^ - avatar
+ 6
How do you even get a 4GB txt file?
1st Feb 2018, 6:24 PM
The Coding Sloth
The Coding Sloth - avatar
+ 6
try this perhaps? from: https://stackoverflow.com/questions/6475328/read-large-text-files-in-JUMP_LINK__&&__python__&&__JUMP_LINK-line-by-line-without-loading-it-in-to-memory import fileinput for line in fileinput.input("filename"): process(line) OR with open("log.txt") as fileobject: for line in fileobject: do_something_with(line)
1st Feb 2018, 7:12 PM
Burey
Burey - avatar
+ 3
maybe readline() method
1st Feb 2018, 7:07 PM
Kuba H
Kuba H - avatar
1st Feb 2018, 9:00 PM
KrOW
KrOW - avatar
3rd Feb 2018, 7:10 PM
EBA
EBA - avatar