Take a look at the code here :
import re, htmlentitydefs
def unescape(text):
def fixup(m):
text = m.group(0)
if text[:2] == "&#":
try:
if text[:3] == "&#x":
return unichr(int(text[3:-1], 16))
else:
return unichr(int(text[2:-1]))
except (ValueError, OverflowError):
pass
else:
try:
text = unichr(htmlentitydefs.name2codepoint[text[1:-1]])
except KeyError:
pass
return text
return re.sub("&#?\w+;", fixup, text)
Of course, this only applies to HTML objects. You may have other semicolons in the text that fiddled with your CSV parser. But I think you already know that ...
UPDATE : added catch for possible OverflowError.
source
share