VideosMy ProjectsProgramming BlogGallery
  1. Home
  2. Blog
  3. Convert bytes into a String in python
Programming Blog

Atom/RSS Feed

python

Convert bytes into a String in python

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

Join my mailing list