Created
December 5, 2011 15:03
-
-
Save miebach/1433874 to your computer and use it in GitHub Desktop.
Guess the encoding of a python string
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 decode_guess(s, etypes=('utf8','latin1','ascii')): | |
""" | |
Returns an unicode object | |
""" | |
for et in etypes: | |
try: | |
return s.decode(et) | |
except UnicodeDecodeError: | |
pass | |
return s.decode('ascii', 'ignore') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment