Unicode problem

gargravarr at whoever.com gargravarr at whoever.com
Wed Mar 20 16:04:13 EST 2002


Thanks for the help! It worked!

Tom

>if you don't tell Python what 8-bit encoding you want
>to use for a Unicode string, Python will assume ASCII.
>
>to convert to an 8-bit string with a known encoding,
>use the encode method:
>
>    s = i.firstChild.data.encode("iso-8859-1")
>
>you should probably escape < > & too; consider using
>something like:
>
>    from cgi import escape
>
>    def encode(s):
>        if not s: return ""
>        return escape(s.encode("iso-8859-1"))
>
>    body.write('<h2>%s</h2>\n' % encode(i.firstChild.data))
>
></F>
>
><!-- (the eff-bot guide to) the python standard library:
>http://www.pythonware.com/people/fredrik/librarybook.htm




More information about the Python-list mailing list