Skip to content

Instantly share code, notes, and snippets.

@Eugeny
Created October 18, 2010 11:18
Show Gist options
  • Save Eugeny/632061 to your computer and use it in GitHub Desktop.
Save Eugeny/632061 to your computer and use it in GitHub Desktop.
class Element(etree.ElementBase):
def __init__(self, tag, *args, **kwargs):
... blah-blah ...
def __setitem__(self, idx, val):
try:
self.set(idx, fix_unicode(val))
except:
print repr(val)
... blah-blah ...
def fix_unicode(s):
s = unicode(unicode(str(s)).encode('utf8', 'xmlcharrefreplace'))
return s
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment