tkinter + unicode + bug or feature??

Bob van der Poel bvdpoel at kootenay.com
Fri Jan 24 21:43:57 EST 2003


Martin v. Löwis wrote:
> Bob van der Poel wrote:
> 
>> Okay. I'll have to look at the MegaWidget stuff later. I'm just 
>> thinking that doing something like 
>> string=entrywidget.get().encode('iso8859-1') should do the trick. Not 
>> sure, though, what encoding to use. Is there a pythonic way to 
>> determine the best to use?


Just as a followup, unless I'm totally missing something here using PWM 
doesn't help.

> 
> Encoding the Unicode string should work, as would comparing it to other 
> Unicode strings - you should try to eliminate all non-ASCII byte strings 
> that represent text; then you can happily compare text strings.

BTW, I really think this is a bug. If you enter "ascii" text into the 
entry box you get() returns a string, if you enter "extended ascii" you 
get a unicode string. And since one can't tell beforehand what the user 
is going to enter... Add to this the fact that the behaviour is not 
documented in the tkinter reference manual (yes, it is the tcl/tk manual).

> There is really no way anybody could tell you what encoding to use: YOU 
> should know what encoding your text strings have - how could we possibly 
> know?

Well, yes. Being on the US-side (altho I do live in Canada and we're a 
bit less centric in our thinking) I was just referring to a "normal" 
encoding...whatever that is :)

> If you want to find out what encoding the user is likely to use, you 
> should use locale.nl_langinfo(locale.CODESET) on POSIX systems, and 
> locale.getlocale()[1] on Windows.

Yes, local.getlocale() works fine. Now, if I do use encode on these 
strings, will I run into problems if the user's locale is not encodable 
into 8bits. Or can that not happen?



-- 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at kootenay.com
WWW:   http://www.kootenay.com/~bvdpoel






More information about the Python-list mailing list