Skip to content

Instantly share code, notes, and snippets.

@jbarciauskas
Created February 1, 2011 20:23
Show Gist options
  • Save jbarciauskas/806579 to your computer and use it in GitHub Desktop.
Save jbarciauskas/806579 to your computer and use it in GitHub Desktop.
import codecs
def unicode_safe_127(ss):
"""safely handle strings with hard ordinal values greater than 127
by escaping each value as appropriate"""
mys = ss
tos=[]
for i,s in enumerate(mys):
if ord(s)>127:
print codecs.unicode_escape_encode(mys)[0]
tos.append(codecs.unicode_escape_encode(s)[0])
else:
tos.append(s)
return "".join(tos)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment