Created
March 22, 2013 22:23
-
-
Save sirrice/5225239 to your computer and use it in GitHub Desktop.
For those times when you have no idea what type of string you received are, and what encoding scheme it's encoded in. Just turn the damn thing into utf-8 unicode.
This file contains 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 get_me_unicode(v): | |
if isinstance(v, unicode): | |
s = v.encode('utf-8', errors='ignore') | |
elif isinstance(v, basestring): | |
s = unicode(v, 'utf-8', errors='ignore').encode('utf-8', errors='ignore') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment