How To Read Files Piece by Piece
Instead of reading the whole file, we are going to learn how to read a file in small chunks
We'll cover the following...
The easiest way to read a file in chunks is to use a loop. First we will learn how to read a file line by line and then we will learn how to read it a kilobyte at a time. We will use a for loop for our first example:
Press + to interact
handle = open("test.txt", "r")for line in handle:print(line)handle.close()
...