I have an array of boolean values in python. How can I write these values to a file as binary, (where each value only requires 1 bit of data to save)?
Asked
Active
Viewed 62 times
0
-
You may be interested in [this](https://stackoverflow.com/questions/17536411/write-individual-bits-to-a-file-in-python) nearly identical question. – brenns10 Jul 16 '15 at 23:45
-
Or perhaps [this](https://stackoverflow.com/questions/21220916/writing-bits-to-a-binary-file) one. – brenns10 Jul 16 '15 at 23:46
-
[Bitarray](https://pypi.python.org/pypi/bitarray/0.8.1) is what you're looking for: `bitarray.bitarray([False, True, True]).tofile(open("hello.txt","wb"))` – Travis Jul 16 '15 at 23:56