I have found at http://wiki.python.org/moin/EscapingXml:
import xml.parsers.expat
def unescape(s):
want_unicode = False
if isinstance(s, unicode):
s = s.encode("utf-8")
want_unicode = True
# the rest of this assumes that `s` is UTF-8
list = []
# create and initialize a parser object
p = xml.parsers.expat.ParserCreate("utf-8")
p.buffer_text = True
p.returns_unicode = want_unicode
p.CharacterDataHandler = list.append
# parse the data wrapped in a dummy element
# (needed so the "document" is well-formed)
p.Parse("<e>", 0)
p.Parse(s, 0)
p.Parse("</e>", 1)
# join the extracted strings and return
es = ""
if want_unicode:
es = u""
return es.join(list)
With
t="""מפתחים
רבים מבקשים
את עזרתי
בפתרון
בעיות של
ביצועי Visual Studio.
\nבד”כ את רוב
הבעיות ניתן
לפתור יחסית
בקלות, \nוככל
שעובר הזמן
אני מוצא את
עצמי מספק
פחות או יותר
את אותן
התשובות, \nמה
שגרם לי
לחשוב
שכנראה הגיע
הזמן להעלות
אותן בצורה
מסודרת
לפוסט."""
print unescape (t)
the result is
מפתחים רבים מבקשים את עזרתי בפתרון בעיות של ביצועי Visual Studio.
בד”כ את רוב הבעיות ניתן לפתור יחסית בקלות,
וככל שעובר הזמן אני מוצא את עצמי מספק פחות או יותר את אותן התשובות,
מה שגרם לי לחשוב שכנראה הגיע הזמן להעלות אותן בצורה מסודרת לפוסט.
I hope it helps.
Regards Martin
2012/6/1 Udi Milo <[email protected]>
> part of my product receives user text, saves it and shows it later.
>
> one of my users added a hebrew text attached below and I do not know how
> to translate it into letter instead of hex.
> simple text.encode('UTF-8') doesn't work, and I am far from being an
> expert in the subject. can someone help me out?
>
> see attached text:
>
> מפתחים רבים
> מבקשים את
> עזרתי
> בפתרון
> בעיות של
> ביצועי Visual Studio.
> בד”כ את רוב
> הבעיות ניתן
> לפתור יחסית
> בקלות,
> וככל שעובר
> הזמן אני
> מוצא את עצמי
> מספק פחות או
> יותר את אותן
> התשובות,
> מה שגרם לי
> לחשוב
> שכנראה הגיע
> הזמן להעלות
> אותן בצורה
> מסודרת
> לפוסט.
>