How to convert bytes type to string type in python

Published: April 30, 2018

DMCA.com Protection Status

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

References

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