def readInChunks(fileObj, chunkSize=2048):
    """
    Lazy function to read a file piece by piece.
    Default chunk size: 2kB.
    """
while True:
    data = fileObj.read(chunkSize)
if not data:
    break
yield data
f = open('bigFile')
for chuck in readInChunks(f):
    do_something(chunk)
How to read large file, line by line in python