Tkinter wart: returned texts are sometimes strings, sometime Unicode strings
aleax at aleax.it
Sat Mar 22 11:12:42 CET 2003
Martin v. Löwis wrote:
> 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 think it might well be, yes.
>> (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.
OK... I sure wouldn't mind a way to get a warning for such
behavior on my program's part -- it sounds like it might be
something one might easily do accidentally, ending up with a
programs that "happens to work in some locales", but might
well prefer to fix upon learning about it. That is, assuming
I'm correctly following your description of what's going on.
More information about the Python-list