How can I convert bytes to a Python string?

PythonProgramming

You need to decode the bytes object to produce a string. This can be done using the decode function from string class that will accept then encoding you want to decode with. 

example

my_str = b"Hello" # b means its a byte string
new_str = my_str.decode('utf-8') # Decode using the utf-8 encoding
print(new_str)

Output

This will give the output −

Hello
raja
Published on 18-Apr-2018 12:23:16
Advertisements