with open('binary.txt',"rb",buffering=-1) as f:
for line in f:
for c in line:
print(c)
With a file like:
"abcde"
Produces
>>>
97
98
99
100
101
The optional buffering argument is described here:
buffering is an optional integer used to set the buffering policy.
Pass 0 to switch buffering off (only allowed in binary mode), 1 to
select line buffering (only usable in text mode), and an integer > 1
to indicate the size of a fixed-size chunk buffer. When no buffering
argument is given, the default buffering policy works as follows:
•Binary files are buffered in fixed-size chunks; the size of the
buffer is chosen using a heuristic trying to determine the underlying
device’s “block size” and falling back on DEFAULT_BUFFER_SIZE. On many
systems, the buffer will typically be 4096 or 8192 bytes long.
Python io.open
And if you were really keen and planned on manipulating them, you can convert each line into a bytearray
line = bytearray(line)
To answer your comment this demonstrates how to filter out which characters you iterate over:
with open('binary.txt',"rb",buffering=-1) as f:
for line in f:
for c in [b for b in line if b in range(663,765)]: #in a certain range
print(c)
for c in [b for b in line if b == 5]: #is a certain number
print(c)