Hello, I'm NEW B who just started Python I want to read a big file one by one and process it I only know how to read the whole thing and then read it one line at a time
I'd like to know if there's another way.
for each_line in fileinput.input(input_file):
do_something(each_line)
for each_line_again in fileinput.input(input_file):
do_something(each_line_again)
The most pythonic way to read files one line at a time is
with open(...) as f:
for line in f:
//Process here
This is.
Buffered-IO automatically manages memory, so you can run large files without any problems
© 2024 OneMinuteCode. All rights reserved.