I have tried this program which is reading my file by characters in chunks which is the behaviour I want
def read_in_chunks(file_object, chunk_size=1024):
    """Lazy function (generator) to read a file piece by piece.
    Default chunk size: 1k."""
    while True:
        data = file_object.read(chunk_size)
        if not data:
            break
        yield data
with open('really_big_file.dat') as f:
    for piece in read_in_chunks(f):
        print(piece)
But When I try to apply the same method using readlines() then it doesn't works for me. Here is the code I am trying..
def read_in_chunks(file_object, chunk_size=5):
    """Lazy function (generator) to read a file piece by piece.
    Default chunk size: 1k."""
    while True:
        data = file_object.readlines()[0:chunk_size]
        if not data:
            break
        yield data
with open('Traefik.log') as f:
    for piece in read_in_chunks(f):
        print(piece)
Can Somebody help me how can I achieve the same chunks behaviour for N number of lines?
 
    