How to convert bytes type to string type in python

To convert a "bytes" type to string type, one can use the decode("utf-8") function:

>>> l = b'hello world'
>>> l
b'hello world'
>>> type(l)
<class 'bytes'>
>>> s = l.decode("utf-8") 
>>> type(s)
<class 'str'>
>>> s
'hello world'

Example of application with ssh tunnek and pexpect: here


Links Site
Convert bytes to a string? stackoverflow
Built-in Types python doc
unicode python doc