0

I am trying to print in a documents bits 1 an 0 and I have the next code

from bitarray import bitarray

a = bitarray()
a.append(True)
a.append(False)
a.append(True)

print(a)

f = file("bits.dat","wb")
f.write(a)
f.close()

It seems that it works but when I open the document bit.dat appears an error that I do not known how to solve.

Screenshot

Any ideas?

jesterjunk
  • 2,342
  • 22
  • 18
victor
  • 9
  • 6

2 Answers2

0

I seems you are just opening the file in a wrong way – you are opening it as if it contained text, which is not the case. The viewer tries to interpret the data as UTF-8-encoded text, but the byte you've made is not valid UTF-8. Just try to view the file as binary data.

user87690
  • 687
  • 3
  • 25
0

You may need a hex editor to open that file, for example:

When I view the (bits.dat) file in a hex editor I get the following.

00000000:  b1                                                           :.
Community
  • 1
  • 1
jesterjunk
  • 2,342
  • 22
  • 18