Reading Binary Files in Python

Reading the contents of a binary file.

Source code :



f = open("file", "rb")
try:
    byte = f.read(1)
    while byte != "":
        byte = f.read(1)
finally:
    f.close()

Output :

Contents of the file will be shown as output

Notes :

Here we will iterate over every bytes to read them.


Output :


                

Comments :