Answers for "reading a file line by line using a generator"

0

reading a file line by line using a generator

def read_file(path, block_size=1024): 
    with open(path, 'rb') as f: 
        while True: 
            piece = f.read(block_size) 
            if piece: 
                yield piece 
            else: 
                return

for piece in read_file(path):
    process_piece(piece)
Posted by: Guest on September-03-2021

Code answers related to "reading a file line by line using a generator"

Python Answers by Framework

Browse Popular Code Answers by Language