Skip to content

Instantly share code, notes, and snippets.

@wrought
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wrought/23e8090c2b74406e59a5 to your computer and use it in GitHub Desktop.
Save wrought/23e8090c2b74406e59a5 to your computer and use it in GitHub Desktop.
to_unicode_or_bust.py
# Use this function to decode early
def to_unicode_or_bust( obj, encoding='utf-8-sig'):
if isinstance(obj, bytes):
obj = unicode(obj, encoding)
return obj
# use .encode('utf-8') to encode late
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment