Thsise Faek
Thsise Faek

Reputation: 311

Read and modify bits from file?

Simple question. Is there a way to read a file in the form of bits (and not bytes or text)? If not, is there a way to convert the bytes that I get from the Python IO (binary mode) into bits?

To add a little context, I am not just trying to read the bits, but also modify them in specific cases and write the modified ones to a new file. I can work with the bits being either in the form of a string or an integer.

EDIT: The data in the original file will be in the form of simple text. What I am trying to do is get the bits that make up each character and modify them to suit my needs.

Upvotes: 0

Views: 1716

Answers (1)

Marichyasana
Marichyasana

Reputation: 3154

There is a python package "bitstring". The manual is here: https://pythonhosted.org/bitstring/ There is a link on that web page to download the package. I have used it and it can read bits from a file.

Upvotes: 1

Related Questions