Problem Statement
What is the memory-friendly way to read a large text file?
Explanation
Iterating over the file object streams one line at a time. Memory stays small even for gigabyte files.
Calling read or readlines pulls the entire content or many lines into memory and can cause spikes.
Code Solution
SolutionRead Only
with open('big.log','r',encoding='utf-8') as f:
for line in f:
handle(line)