os.path query functions behavior incorrect?

Beman Dawes beman at acm.org
Tue Apr 5 12:12:40 EDT 2005


The docs for os.path.exists(), isdir(), and the like, do not describe 
behavior when an I/O error occurs.

Testing on Windows XP SP2 with Python 2.4.1 (#65, Mar 30 2005, 09:13:57) 
[MSC v.1310 32 bit (Intel)] on win32, on a machine with no a: drive, c: is a 
hard disk with a top level directory named "path" but without a top level 
directory named "foo", and d: is a CD drive (with no disc inserted):

>>> import os
>>> print os.path.exists("c:\\")
True
>>> print os.path.isdir("c:\\")
True
>>> print os.path.isdir("c:\\boost")
True
>>> print os.path.isdir("c:\\foo")
False

OK, that meets my expectations. But now:

>>> print os.path.exists("a:\\")
False
>>> print os.path.isdir("a:\\")
False
>>> print os.path.exists("d:\\")
True
>>> print os.path.isdir("d:\\")
True

These to me are I/O errors that should result in an exception. Doing a 
command line dir a:\ reports "The system cannot find the path specified." 
Dir d:\ reports "The device is not ready."

So are these os.path functions specified and implemented incorrectly? Should 
they instead throw exceptions for the above examples?

If they are specified and implemented correctly, what is the rationale for 
this behavior?


Thanks,

--Beman 





More information about the Python-list mailing list