Tkinter wart: returned texts are sometimes strings, sometime Unicode strings

Martin v. Löwis martin at v.loewis.de
Fri Mar 21 12:29:43 EST 2003


Alex Martelli <aleax at aleax.it> writes:

> A better fix might be to modify _tkinter.c to avoid the "smart"
> way PyTclObject_string now strives to return plain string
> objects when all contents are ASCII:

Would it be desirable to have this as a runtime configuration option?

[...]
> I'm not sure what this could break 

At the time this code was added, I believe there were reported
breakages. Not sure whether the same code would break with the current
Python still.

> (indeed, I'm not even sure the fallback to returning a string if
> decoding as utf-8 faiils is even warranted).

Unfortunately, there is: When people pass a byte string to Tkinter
that has non-ASCII non-UTF8 sequences, Tk will assume it is encoded in
the locale's encoding, and render it as such. On returning it back to
Python, it will return it as it originally was, which may mean that
decoding to UTF-8 will fail.

Regards,
Martin





More information about the Python-list mailing list