[Python-bugs-list] [ python-Bugs-738617 ] On Windows, os.listdir() throws incorrect exception
SourceForge.net
noreply@sourceforge.net
Sun, 18 May 2003 18:53:25 -0700
Bugs item #738617, was opened at 2003-05-16 13:11
Message generated for change (Comment added) made by mikethompson
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=738617&group_id=5470
Category: None
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Mike Thompson (mikethompson)
Assigned to: Nobody/Anonymous (nobody)
Summary: On Windows, os.listdir() throws incorrect exception
Initial Comment:
ActivePython 2.2.2 Build 224 (ActiveState Corp.) based
on
Python 2.2.2 (#37, Nov 26 2002, 10:24:37) [MSC 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import os
>>> os.listdir('c:\IMPOSSIBLE')
Traceback (most recent call last):
File "<stdin>", line 2, in ?
WindowsError: [Errno 3] The system cannot find the
path specified:
'c:\IMPOSSIBLE/*.*'
This is the wrong exception I would have thought.
AIUI, WindowsError is thrown for uniquely Windows
types of problems. Path not found is not unique to
Windows.
I would have expected an os.error exception to have
been thrown together with an code of errno.ENOENT.
This is what happens if I try to open() a non existent file.
(Caution: I'm a python newbie and I could easily have
missed something here -- If so sorry to waste your time)
The deadly part about this bug is that WindowsError
subclasses os.error, just the code changes (3 instead of
2). So my "except os.error" worked to catch the
exception ... just the error code seemed wrong. Took
be ages to figure it all out.
----------------------------------------------------------------------
>Comment By: Mike Thompson (mikethompson)
Date: 2003-05-19 11:53
Message:
Logged In: YES
user_id=630223
Yet, if I try to open() a non existent file, this mapping to a
generic Python exception DOES occur (exception is os.error,
code is errno.ENOENT)
And just as well it does too because otherwise cross-platform
coding would be difficult.
Now, if its good enough for open(), why not for os.listdir()?
>From the documentation, I got the impression that
WindowError gets used for Windows specific problems for
which generic cross-platform handling makes no sense,
which is why WindowsError simply wraps errno/GetLastError
() and sub-classes the standard exception.
----------------------------------------------------------------------
Comment By: Jeff Epler (jepler)
Date: 2003-05-19 11:33
Message:
Logged In: YES
user_id=2772
Python faithfully relays to you the information returned by the OS in these cases. I don't think it's planned for Python to try to rationalize the various errno/GetLastError() values based on what it thinks the actual error must have been.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=738617&group_id=5470