os.path query functions behavior incorrect?

B

Beman Dawes

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):
False

OK, that meets my expectations. But now:
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
 
M

Mike Rovner

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

Works for me. (Win XP SP2, Py 2.4, only have c and d drives)
 
W

wittempj

It works fine under linux
martin@ubuntu:~ $ python
Python 2.3.4 (#2, Feb 2 2005, 11:10:56)
[GCC 3.3.4 (Debian 1:3.3.4-9ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
 
G

Georg Brandl

It works fine under linux
martin@ubuntu:~ $ python
Python 2.3.4 (#2, Feb 2 2005, 11:10:56)
[GCC 3.3.4 (Debian 1:3.3.4-9ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Of course it does. This is not a problem with Unix-style filesystems
because there a directory either exists or not. However, under Windows,
the drive letters for floppies or CDs exists even if there is no media
inserted. It is, of course, questionable whether isdir() and exists()
should return True in this case.

mfg
Georg
 
S

Simon Percivall

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."

The functions use the underlying C library, and in this case, the
result is not guaranteed by the standard.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top