Skip to content

Instantly share code, notes, and snippets.

@silviud
Created March 17, 2014 13:44
Show Gist options
  • Save silviud/9599403 to your computer and use it in GitHub Desktop.
Save silviud/9599403 to your computer and use it in GitHub Desktop.
Encode utf python
def try_utf8(data):
"Returns a Unicode object on success, or None on failure"
try:
return data.decode('utf-8')
except UnicodeDecodeError, ue:
print ue
return None
# vim e! ++enc=utf8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment