sax barfs on unicode filenames

"Martin v. Löwis" martin at
Wed Oct 4 16:36:54 EDT 2006

Fredrik Lundh schrieb:
> Diez B. Roggisch wrote:
>> Filenames are expected to be bytestrings. So what happens is that the
>> unicode string you pass as filename gets implicitly converted using the
>> default encoding.
> it is ?

Yes. While you can pass Unicode strings as file names to many Python
functions, you can't pass them to Expat, as Expat requires the file name
as a byte string. Hence the error.


P.S. and just to anticipate nit-picking: yes, you can pass a Unicode
string to Expat, too, as long as the Unicode string only contains
ASCII characters. And yes, it doesn't have to be ASCII, if you change
the system default encoding.

More information about the Python-list mailing list