Iterating over a binary file

Derek none at
Tue Jan 6 21:25:11 CET 2004

Pardon the newbie question, but how can I iterate over blocks of data
from a binary file (i.e., I can't just iterate over lines, because
there may be no end-of-line delimiters at all).  Essentially I want to
to this:

f = file(filename, 'rb')
data =
while len(data) > 0:
    data =

The above code works, but I don't like making two read() calls.  Any
way to avoid it, or a more elegant syntax?  Thanks.

More information about the Python-list mailing list