Convert bytes to a string
Decode the byte string and turn it in to a character (Unicode) string.
Python 3:
encoding = 'utf-8'
b'hello'.decode(encoding)
or
str(b'hello', encoding)
Python 2:
encoding = 'utf-8'
'hello'.decode(encoding)
or
unicode('hello', encoding)
Decode the bytes
object to produce a string:
>>> b"abcde".decode("utf-8")
'abcde'
The above example assumes that the bytes
object is in UTF-8, because it is a common encoding. However, you should use the encoding your data is actually in!