Created
March 24, 2015 16:02
-
-
Save chris-jamieson/b0bded976eb8c60b44ea to your computer and use it in GitHub Desktop.
Python convert from unicode
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
| # original from http://stackoverflow.com/questions/13101653/python-convert-complex-dictionary-of-strings-from-unicode-to-ascii | |
| def convert_from_unicode(input): | |
| if isinstance(input, dict): | |
| return dict((convert_from_unicode(key), convert_from_unicode(value)) for key, value in input.iteritems()) | |
| elif isinstance(input, list): | |
| return [convert_from_unicode(element) for element in input] | |
| elif isinstance(input, unicode): | |
| return input.encode('utf-8') | |
| else: | |
| return input |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment