Skip to content

Instantly share code, notes, and snippets.

@RonenNess
Last active January 17, 2018 11:34
Show Gist options
  • Save RonenNess/0819c8cdb716b5eefee9 to your computer and use it in GitHub Desktop.
Save RonenNess/0819c8cdb716b5eefee9 to your computer and use it in GitHub Desktop.
two useful python function to switch between str and unicode
def to_str(text):
'''
convert unicode to string
'''
try:
return str(text)
except:
return str(text.encode("utf-8"))
def to_unicode(text):
'''
convert string to unicode
'''
try:
return unicode(text.decode("utf-8"))
except:
return unicode(text)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment