Created
March 17, 2014 18:10
-
-
Save armon/9604953 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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