I have a very big file 4GB and when I try to read it my computer hangs. So I want to read it piece by piece and after processing each piece store the processed piece into another file and read next piece.
Is there any method to yield these pieces ?
I would love to have a lazy method.
To write a lazy function, just use
yield:Another option would be to use
iterand a helper function:If the file is line-based, the file object is already a lazy generator of lines: