Bootstrap FreeKB - Python (Scripting) - Convert byte to string
Python (Scripting) - Convert byte to string

Updated:   |  Python (Scripting) articles

Let's say you have a list that contains byte objects.

for item in items:
  print(item)

 

You will know the objects are bytes as each element will begin with b.

b'foo'
b'bar'

 

decode can be used to convert the byte objects into strings.

for item in items:
  print(item.decode('utf-8'))

 

Or ascii.

for item in items:
  print(item.decode('ascii'))

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter eb82b2 in the box below so that we can be sure you are a human.