Last active
August 29, 2015 14:05
-
-
Save gtt116/a43192f8ebf1992e5806 to your computer and use it in GitHub Desktop.
to_unicode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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