Skip to content

Instantly share code, notes, and snippets.

@gtt116
Last active August 29, 2015 14:05
Show Gist options
  • Save gtt116/a43192f8ebf1992e5806 to your computer and use it in GitHub Desktop.
Save gtt116/a43192f8ebf1992e5806 to your computer and use it in GitHub Desktop.
to_unicode
# Borrow from http://farmdev.com/talks/unicode/
#
# Remember:
# file/network (8-bit string) ----decode() -----> unicode -----encode()--------> file/network
def to_unicode(obj, decoding='utf8'):
"""
decoding a 8-bit string to unicode
"""
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, decoding)
return obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment