Skip to content
Advertisement

How to convert bytearray with non-ASCII bytes to string in python?

I don’t know how to convert Python’s bitarray to string if it contains non-ASCII bytes. Example:

JavaScript

In my example, I just want to somehow get a string ‘x9f’ back from the bytearray. Is that possible?

Advertisement

Answer

In Python 2, just pass it to str():

JavaScript

In Python 3, you’d want to convert it back to a bytes object:

JavaScript
Advertisement