[Python-Dev] Python-3.0, unicode, and os.environ

Terry Reedy tjreedy at udel.edu
Sun Dec 7 22:20:06 CET 2008

Toshio Kuratomi wrote:

>   - If this is true, a definition of os.listdir(<type 'str'>) that would
> better meet programmer expectation would be: "Give me all files in a
> directory with the output as str type".  The definition of
> os.listdir(<type 'bytes'>) would be "Give me all files in a directory
> with the output as bytes type".  Raising an exception when the filenames
> are undecodable is perfectly reasonable in this situation.

Your examples (snipped) pretty well convince me that there is a use case 
for raising exceptions.  We should move beyond arguing over which one 
way is right.  I think there should be a second argument 
'ignorebad=False' to ignore undecodable files rather than raise the 
exception (or 'strict=True' to stop and raise exception on non-decodable 
names -- then code is 'if strict: raise ...').  I believe other 
functions have a similar parameter.


More information about the Python-Dev mailing list