[xml] convert funny chars to char entites?

Martin v. Löwis loewis at informatik.hu-berlin.de
Mon Sep 16 04:46:55 EDT 2002


":B nerdy" <thoa0025 at mail.usyd.edu.au> writes:

> Traceback (most recent call last):
>   File "./batch-maid.py", line 85, in ?
>     generate_browse_options()
>   File "./batch-maid.py", line 70, in generate_browse_options
>     f.write(options_composer)
> UnicodeError: ASCII encoding error: ordinal not in range(128)
> 
> whats going on?

You should start with telling us what f is, and what options_composer
is. How are we supposed to know?

> how can i fix it?

I assume f is a file object, and options_composer is a Unicode
object. In that case, you need to determine the encoding you want to
use, and encode the Unicode object, e.g. with

  f.write(options_composer.encode("utf-8"))

Regards,
Martin




More information about the Python-list mailing list