Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #reading #file #line #line #generator
ADD COMMENT
Topic
Name
2+7 =