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 |
Is python a compiled or interpreted language?
Can you tell the difference between break and continue in python?
What advantages does Python offer as a programming tool in today's environment?
What do you mean by list comprehension?
Why python language is called python?
How to count the number of instance?
How we can send email from python?
Can you explain the life cycle of a thread?
What is the comment tag in Python ?
How do you iterate over a list and pull element indices at the same time?
Explain important characteristics of python objects?
Mention the floor division available in python