[XML-SIG] outputting non-ascii strings

Matt Patterson matt@reprocessed.org
Wed, 22 May 2002 16:44:34 +0100


Hello,

I've been lurking on this list for a while and am trying my hand at some
SAX processing for the first time. I've done a small amount of DOM
processing, but I'm still a relative Python newbie. I've run into an
irritating and (hopefully) newbie-related problem:

Parsing an XML file containing Unicode characters using SAX works fine,
until I actually want to output the character stream somewhere: having
tried print() and write() I've hit the same error - the unicode text is
being automatically converted to 7-bit ASCII and the non ASCII
characters (typographer's quotes, in this case) are causing the
operation to fail:

> Traceback (most recent call last):
>   File "./reprocessed_generate.py", line 16, in ?
>     outputFile.write(cHandler.body)
> UnicodeError: ASCII encoding error: ordinal not in range(128)

How can I output a UTF-8 text file? (Or output UTF-8 strings to stdout,
for that matter.)

Thank you

Matt


-- 
   Matt Patterson | Typographer
   <matt@reprocessed.org> | http://reprocessed.org/