Python Read Binary File

This day I have a problem to create Python read binary file. I have a binary file and want to create ptyhon to read binary file. Reading binary file with python is very simple. We can use ‘open’ function and adding parameter ‘b’ if we wanto to python read binary file. This is a simple code how to read binary file with python :

From this example, I try to create python read binary file with size of data is 3200 byte. If we wanto to display output from this data, we can use command :

Output from this command is character from 3200 byte from our input file. We can display our data in integer representing the Unicode code point of the character use command ord. For example, ord(‘a’) returns the integer 97. So, if we want to display our data in integer, we can loop our data and convert that with ord command. This is a simple code how to do that :

This is my simple posting about to create python read binary file code. In my next post, I will create a tutorial how Python write binary file.

Leave a Reply

Your email address will not be published. Required fields are marked *

 

This site uses Akismet to reduce spam. Learn how your comment data is processed.