By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,587 Members | 1,575 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,587 IT Pros & Developers. It's quick & easy.

os.path query functions behavior incorrect?

P: n/a
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
Jul 18 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Beman Dawes wrote:
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)
os.path.exists('d:\\') True os.path.exists('e:\\') False os.path.exists('a:\\') False


Jul 18 '05 #2

P: n/a
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.
import os.path
os.path.exists('/blah') False os.path.isdir('/blah') False os.path.isdir('/home/martin') True os.path.exists('/home/martin') True


Jul 18 '05 #3

P: n/a
wi******@hotmail.com wrote:
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.
import os.path
os.path.exists('/blah') False os.path.isdir('/blah') False os.path.isdir('/home/martin') True os.path.exists('/home/martin') True


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
Jul 18 '05 #4

P: n/a
> 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.

Jul 18 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.