Re: Wanted: python script to convert to/from UTF-8 to/from XML Entities
- From: Fredrik Lundh <fredrik@xxxxxxxxxxxxxx>
- Date: Sat, 30 Aug 2008 18:54:43 +0200
Siegfried Heintze wrote:
Does someone have a little python script that will read a file in UTF-8/UTF-16/UTF-32 (my choice) and search for all the characters between 0x7f-0xffffff and convert them to an ASCII digit string that begins with "&#" and ends with ";" and output the whole thing? If not, could someone tell me how to write one?
file = open("filename.txt", "rb")
text = file.read()
text = unicode(text, "utf-8")
text = text.encode("ascii", "xmlcharrefreplace")
print text
tweak as necessary.
</F>
.
- References:
- Wanted: python script to convert to/from UTF-8 to/from XML Entities
- From: Siegfried Heintze
- Wanted: python script to convert to/from UTF-8 to/from XML Entities
- Prev by Date: Wanted: python script to convert to/from UTF-8 to/from XML Entities
- Next by Date: Wholesale Air Jordan Six Rings (6 IX Rings) sneakers (www.sneakers-in-china.com)
- Previous by thread: Wanted: python script to convert to/from UTF-8 to/from XML Entities
- Next by thread: Wholesale Air Jordan Six Rings (6 IX Rings) sneakers (www.sneakers-in-china.com)
- Index(es):