Write a program to read and write the binary data using python?



Write a program to read and write the binary data using python?..

Answer / chaitanya

The module that is used to write and read the binary data is known as struct. This module allows the functionality and with it many functionalities to be used that consists 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 more organized fashion.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Python Interview Questions

What does ** (double star/asterisk) and * (star/asterisk) do for parameters?

0 Answers  


What is __ init __( self in python?

0 Answers  


How do I run a script in python shell?

0 Answers  


What is use of @classmethod, @staticmethod, @property in python?

0 Answers  


How do you include a module in your python file?

0 Answers  






What is the comment tag in Python ?

0 Answers   Microsoft,


Tell me what's the process to get the home directory using ‘~' in python?

0 Answers  


How do you check whether the two variables are pointing to the same object in python?

0 Answers  


What is the purpose of #!/usr/bin/pythonon the first line in the above code? Is there any advantage?

0 Answers  


What does __ init __ mean in python?

0 Answers  


Is there a switch or case statement in python?

0 Answers  


Should I learn r or python first?

0 Answers  


Categories