ilanschnell/bitarray — Issue #1: bitarray.tostring behavior change between 0.3.5 and 0.4.0
Author: tvo
Created: 2012-01-23 15:12:25+00:00
State: open

Hi,

I'm using bitarray, and I noticed a change in behavior of tostring.

In 0.3.5, the following code works:

>>> from bitarray import bitarray
>>> bitarray("11111111").tostring()
'\xff'

While in 0.4.0 and HEAD, it doesn't work:

>>> from bitarray import bitarray
>>> bitarray("11111111").tostring()
Traceback (most recent call last):
File "", line 1, in
File "/home/.../virtualenv/lib/python2.7/site-packages/bitarray/__init__.py", line 91, in tostring
return self.tobytes().decode()
UnicodeDecodeError: 'ascii' codec can't decode byte 0xff in position 0: ordinal not in range(128)

I noticed in 0.4.0 also `tobytes()` and `frombytes()` have been introduced. So my question is: is the change in behavior of `tostring()` intended and should I update my code to use `tobytes()` if bitarray >= 0.4.0 is detected, or is this change of behavior a bug in bitarray?

-Tobi