Help with Unicode? in Tkinter?

Sheila King sheila at spamcop.net
Sun Sep 2 12:45:36 EDT 2001


On Sun, 2 Sep 2001 15:03:20 +0400 (MSD), Oleg Broytmann <phd at phd.pp.ru>
wrote in comp.lang.python in article
<mailman.999428762.4467.python-list at python.org>:

:On Sat, 1 Sep 2001, Sheila King wrote:
:SK> >>> print unichr(231)
:SK> Traceback (most recent call last):
:SK>   File "<pyshell#2>", line 1, in ?
:SK>     print unichr(231)
:SK> UnicodeError: ASCII encoding error: ordinal not in range(128)
:
:   This error indicates that you didn't edit your site.py (or
:sitecustomize.py) and didn't chnge default "ascii" encoding to the encoding
:of your terminal/locale.

Are you sure? I tried changing my locale to France, and I still get the
same errors I was getting when my locale was not France:


Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
IDLE 0.8 -- press F1 for help
>>> import locale
>>> loc = locale.setlocale(locale.LC_ALL)
>>> locale.setlocale(locale.LC_ALL, 'fr')
'French_France.1252'
>>> print u'\xe7'
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in ?
    print u'\xe7'
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> print unichr(231)
Traceback (most recent call last):
  File "<pyshell#4>", line 1, in ?
    print unichr(231)
UnicodeError: ASCII encoding error: ordinal not in range(128)
>>> print chr(231)
ç
>>> 

Although, note that printing the ordinal 231 as a chr instead of as a
unichr works just fine.

Here is an interesting snippet, that I executed immediately following
the above:

>>> import string
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz\x83\x8a\x8c\x8e\x9a\x9c\x9e\x9f\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\xff'
>>> print string.letters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzƒŠŒŽšœžŸÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõöøùúûüýþÿ
>>> locale.setlocale(locale.LC_ALL, loc)
'C'
>>> string.letters
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
>>> print string.letters
ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz
>>> 

I guess I have found a way to proceed, thanks to Ignacio's suggestion. I
wonder if this is the usual way?

--
Sheila King
http://www.thinkspot.net/sheila/
http://www.k12groups.org/




More information about the Python-list mailing list