Python - Read file chunk by chunk

Description

Read file chunk by chunk

Demo

file = open('main.py', 'rb') 
while True: # w  w  w.j  ava2 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