How to read a file byte by byte in Python?
Posted
by zaplec
on Stack Overflow
See other posts from Stack Overflow
or by zaplec
Published on 2010-05-20T09:14:57Z
Indexed on
2010/05/20
9:20 UTC
Read the original article
Hit count: 304
Hi,
I'm trying to read a file byte by byte, but I'm not sure how to do that. I'm trying to do it like that:
file = open(filename, 'rb')
while 1:
byte = file.read(8)
# Do something...
So does that make the variable byte to contain 8 next bits at the beginning of every loop? It doesn't matter what those bytes really are. The only thing that matters is that I need to read a file in 8-bit stacks.
© Stack Overflow or respective owner