cannot open file with non-ASCII filename

eryk sun eryksun at gmail.com
Mon Dec 14 22:20:18 EST 2015


On Mon, Dec 14, 2015 at 6:07 PM, Laura Creighton <lac at openend.se> wrote:
> In a message of Mon, 14 Dec 2015 23:41:21 +0100, "Thomas 'PointedEars' Lahn" wr
> ites:
>
>>Why do you have to use msvcrt?
>>
>>I would use curses for user input, but:
>>
>>,-<https://docs.python.org/2/howto/curses.html?highlight=user%20input>
>>,-<https://docs.python.org/3.2/howto/curses.html?highlight=user%20input>
>>|
>>| No one has made a Windows port of the curses module. On a Windows
>>| platform, try the Console module written by Fredrik Lundh. The Console
>>| module provides cursor-addressable text output, plus full support for
>>| mouse and keyboard input, and is available from
>>| http://effbot.org/zone/console-index.htm.
>>
>>So you should try that instead.
>
> If going for curses, I'd try this instead:
> http://pdcurses.sourceforge.net/

Christoph Gohlke has an extension module based on PDCurses [1]. The
good news for Python 3 users is that it uses the [W]ide-character
console API, such as ReadConsoleInputW. Also, its _get_key_count [2]
function is designed to support the alt numpad event sequences that
the system creates for the input filepath when dragging a file into
the console. In my limited testing, dragging filepaths from Explorer
worked without a hitch using a random Latin-1 name "¨°¸ÀÈÐØàèðø" and a
Latin Extended-B name "ƠƨưƸǀLjǐǘǠǨǰǸ".

Unfortunately the Python 2.7 version is linked against the [A]NSI API,
which maps each Unicode character to either the closest matching
character in the console's codepage or "?". Moreover the PDCurses code
has a bug in narrow builds in that it returns the UnicodeChar from the
KEY_EVENT_RECORD [3] instead of the AsciiChar (the name is a
misnomer). In this case the high byte is junk. You can mask it out
using a bitwise & with 0xFF.

That said, IIRC, the OP wants to avoid using any frameworks such as
curses or a GUI toolkit.

[1]: http://www.lfd.uci.edu/~gohlke/pythonlibs/#curses
[2]: https://github.com/wmcbrine/PDCurses/blob/PDCurses_3_4/win32/pdckbd.c#L259
[3]: https://msdn.microsoft.com/en-us/library/ms684166



More information about the Python-list mailing list