Skip to content

Instantly share code, notes, and snippets.

@mpurzynski
Created August 11, 2017 00:29
Show Gist options
  • Select an option

  • Save mpurzynski/1aabdfbb20ca48723b34283c09816b57 to your computer and use it in GitHub Desktop.

Select an option

Save mpurzynski/1aabdfbb20ca48723b34283c09816b57 to your computer and use it in GitHub Desktop.
def toUnicode(obj, encoding='utf-8'):
if type(obj) in [int, long, float, complex]:
# likely a number, convert it to string to get to unicode
obj = str(obj)
if isinstance(obj, basestring):
if not isinstance(obj, unicode):
obj = unicode(obj, encoding)
return obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment