[Idle-dev] Re: [Tutor] IDLE has problem with Umlaute
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Mon, 6 May 2002 11:12:34 -0700 (PDT)
> print "Gr=F6=DFtes Problem: Umlaute"
>
> from an IDLE editor window, I got the error
> messages:
>
>
> >>> Exception in Tkinter callback
> Traceback (most recent call last):
> File "C:\Python22\lib\lib-tk\Tkinter.py", line 1292, in __call__
> return apply(self.func, args)
> File "C:\Python22\Tools\idle\IOBinding.py", line 136, in save_as
> if self.writefile(filename):
> File "C:\Python22\Tools\idle\IOBinding.py", line 154, in writefile
> f.write(chars)
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
> So IDLE seems to prohibit the use of "=C4=D6=DC=E4=F6=FC=DF" . For German=
native
> speakers i consider this to be a serious drawback, especially when
> using it with students.
Hi Gregor,
It's a unicode encoding thing: you'll need to set the 'default encoding'
scheme of your system to 'iso-8859-1', which is the encoding scheme for
Central Europe. For example:
###
>>> s =3D ""
>>> s
'\xc4\xd6\xdc\xe4\xf6\xfc\xdf'
>>> unicode(s)
Traceback (most recent call last):
File "<stdin>", line 1, in ?
UnicodeError: ASCII decoding error: ordinal not in range(128)
>>> unicode(s, 'iso-8859-1')
u'\xc4\xd6\xdc\xe4\xf6\xfc\xdf'
###
There should be a way to set this up site-wide so that all of Python knows
that it should use the Central European encoding... checking... Ah!
http://www.faqts.com/knowledge_base/view.phtml/aid/11712
mentions something about this, but I don't see sys.setdefaultencoding() in
my interpreter session...
Doh. That's because site.py removes sys.setdefaultencoding() after Python
loads up:
### site.py
#
# Remove sys.setdefaultencoding() so that users cannot change the
# encoding after initialization. The test for presence is needed when
# this module is run as a script, because this code is executed twice.
#
if hasattr(sys, "setdefaultencoding"):
del sys.setdefaultencoding
###
So you'll need to call sys.setdefaultencoding() within sitecustomize.py to
have this work sitewide.
Hope this helps. Good luck!