[issue9820] Windows : os.listdir(b'.') doesn't raise an error for unencodable filenames

Martin v. Löwis report at bugs.python.org
Sun Sep 12 19:12:20 CEST 2010


Martin v. Löwis <martin at v.loewis.de> added the comment:

> You know directly that os.listdir(bytes) is unable to encode the
> filename, instead of manipulate an invalid filename (b'?') and get
> the error later (when you use the filename: open, copy, delete, ...
> the file).

Ok. Then I'm -1 on the patch: you can't know whether the application
actually wants to open the file. Perhaps it only wants to display the
file names, or perhaps it only wants to open some of the files, or
only traverse into subdirectories.

For backwards compatibility, I recommend to leave things as they are.
FindFirst/NextFileA will also do some other interesting conversions,
such as the best-fit conversion (which the "mbcs" code doesn't do
(anymore?)).

Windows has explicit A and W versions, and Python has explicit A
and W types, so it's IMO best to pair them in the natural way
(even if that means code duplication).

> Anywy, on Windows, it's not a good idea to manipulate bytes
> filenames. So it's also a way to encourage people to migrate their
> applications to unicode on Windows.

Only if people run into the issue (which few people will). People
which *do* run into the issue will likely get an error either
way, which will teach them their lesson :-)

----------
title: Windows : os.listdir(b'.') doesn't raise an error for unencodable filenames -> Windows : os.listdir(b'.') doesn't raise an error for	unencodable filenames

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9820>
_______________________________________


More information about the Python-bugs-list mailing list