Reading binary file and looping over each byte

前端 未结 12 1089
孤街浪徒
孤街浪徒 2020-11-22 00:53

In Python, how do I read in a binary file and loop over each byte of that file?

12条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-11-22 01:33

    Python 3, read all of the file at once:

    with open("filename", "rb") as binary_file:
        # Read the whole file at once
        data = binary_file.read()
        print(data)
    

    You can iterate whatever you want using data variable.

提交回复
热议问题