idle 1.6 bug on Windows?

Fredrik Lundh effbot at telia.com
Wed Sep 6 12:47:00 EDT 2000


Syver Enstad wrote:
> Using Python 1.6 final on Windows 2000 Professional.
>
> When I try to open one of my source files I get a traceback.
>
> Traceback (most recent call last):
>   File "G:\Program Files\Python\lib\lib-tk\Tkinter.py", line 766, in
> __call__
>     return apply(self.func, args)
>   File "G:\PROGRA~1\Python\Tools\idle\IOBinding.py", line 71, in open
>     self.editwin.flist.open(filename)
>   File "G:\PROGRA~1\Python\Tools\idle\FileList.py", line 39, in open
>     if os.path.isdir(filename):
>   File "G:\Program Files\Python\lib\ntpath.py", line 216, in isdir
>     st = os.stat(path)
> UnicodeError: ASCII encoding error: ordinal not in range(128)
>
> The path to the file is "E:\VÕre
> dokumenter\Kode\pythonscript\pythonaddin.py" so I guess it's the a with a
> ring that's causing it. Any suggestions as to how to make it work?
>
> Is it best to continue using the 1.5.2 version of Python when using Windows?

tricky.

In 1.6 and later, Tk (and Tkinter) uses Unicode throughout.
Return values from Tk are returned as ordinary strings if they
only contain ASCII characters, and Unicode strings otherwise.

The problem here is that the os.stat function don't know what
to do with a Unicode string that contains non-ASCII characters
(this is true for both 1.6final and 2.0b1).

:::

The right way to fix this is to teach os.stat (and all the other
stdio/posix functions) to convert unicode to 8-bit strings using
the system encoding (as returned by locale.getdefaultlocale())

:::

But for now, it's probably easier to fix this in IDLE or maybe in
the Tkinter interface layer.  try changing the _fixresult method
in Lib/lib-tk/tkFileDialog.py to (untested):

    def _fixresult(self, widget, result):
        if result:
            # use system encoding for filenames
            import locale
            lang, encoding = locale.getdefaultlocale()
            result = result.encode(encoding)
            # keep directory and filename until next time
            import os
            path, file = os.path.split(result)
            self.options["initialdir"] = path
            self.options["initialfile"] = file
        self.filename = result # compatibility
        return result

</F>

<!-- daily news from the python universe:
http://www.pythonware.com/daily/index.htm
-->




More information about the Python-list mailing list