0 votes
in Python by
Write a program to read and write the binary data using python?

1 Answer

0 votes
by

The module which is used to write and read the binary data is known as struct. This module allows many functionalities to be used that consist of the string class. This class contains the binary data that is in the form of numbers that gets converted in python objects for use and vice versa. The program can read or write the binary data is:

import struct

f = open(file-name, "rb")

# This Open() method allows the file to get opened in binary mode to make it portable for # use.

s = f.read(8)

x, y, z = struct.unpack(">hhl", s)

The ‘>” is used to show the format string that allows the string to be converted in big-endian data form. For homogenous list of data the array module can be used that will allow the data to be kept in more organized fashion.

Related questions

+1 vote
asked Feb 13, 2023 in Python by rajeshsharma
+1 vote
asked Oct 28, 2022 in Python by SakshiSharma
...