Skip to content

Instantly share code, notes, and snippets.

@armon
Created March 17, 2014 18:10
Show Gist options
  • Save armon/9604953 to your computer and use it in GitHub Desktop.
Save armon/9604953 to your computer and use it in GitHub Desktop.
def unicode_hammer(s):
if !isinstance(s, unicode):
return s
for enc in ("utf-8","utf-16", "utf-32", "latin-1"):
try:
return s.encode(enc, "replace")
except:
pass
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment