Python 2: Converting bytes array to String

This handy little snippet lets you convert an array of bytes to a string.

u"".join(map(unichr, bytesArray))

If you know you're working with ASCII, you can replace unichr with chr.

Once you got the string, you'll have to determine if decoding the string is necessary. You'll kinda have to know/guess the input encoding before you can convert it properly for 100% coverage.


Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog