Python - Read file chunk by chunk

Description

Read file chunk by chunk

Demo

file = open('main.py', 'rb') 
while True: # from   w  w w  .j av a  2  s  .c o  m
    chunk = file.read(10)       # Read byte chunks: up to 10 bytes 
    if not chunk: break 
    print(chunk)

Result

You typically read binary data in blocks.

Related Example