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

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What flask is and its benefits?

442


How does break work in python?

453


Python ­ How do you make a higher order function in Python?

526


Where is python best used?

459


How do you parse a json file in python?

452






Tell me what are the tools that help to find bugs or perform static analysis?

441


What is the dictionary?

509


What are basic overloading methods in python?

431


Is python faster than c#?

441


How to pass optional or keyword parameters from one function to another in python?

470


How do you use n in python?

413


Is empty string python?

447


How do I kill a python server?

448


What a blank curly brace initialize? A dictionary or a set?

540


I am from non technical Background. In how many days I can learn the python? and What I need to do for that?

1877