Convert bytes into a String in python
I recently needed to convert a bytes object into a readable string format. I found that I could do so very easily using the following method.
Start with a bytes object
str = b'johnwiseman'
Convert bytes to String
You can convert the bytes value into a string value by decoding it into utf-8
.decode("utf-8")
For example
str = b'johnwiseman'
print str.decode("utf-8")
johnwiseman
Alternatively
print str(b'johnwiseman', "utf-8")
johnwiseman