Read file chunk by chunk
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)
You typically read binary data in blocks.