Python (Scripting) - Convert byte to string

by
Jeremy Canfield |
Updated: October 28 2023
| 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