473,324 Members | 2,193 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

os.path query functions behavior incorrect?

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
4 1932
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
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
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
> 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Sims | last post by:
Hi, I have a few 'secure' area where the user needs to log-in b4 they can make view it. I know how to redirect them to the login page but how can I return them to the page they were? if I...
1
by: David | last post by:
Hi everyone. I have read every page that Google returns on this topic, but can't find anything that resolves my problem. Basically, I have an Access Database that does a number of different...
12
by: Xah Lee | last post by:
Python Doc Problem Example Quote from: http://docs.python.org/lib/module-os.path.html ---------- split( path) Split the pathname path into a pair, (head, tail) where tail is the last...
6
by: Steven D.Arnold | last post by:
I have a query which does not use column indexes that it should use. I have discovered some interesting behaviors of Postgres which may indicate a bug in the database's query planning. Take a...
9
by: Clinton Frankland | last post by:
Hi, On a Windows 2000 Server when attempting to use System.IO.Directory.CreateDirectory(string.concat(Server.MapPath(""), "\verify")) I receive a System.IO.DirectoryNotFoundException error:...
2
by: Zygo Blaxell | last post by:
I have a table with a few million rows of temperature data keyed by timestamp. I want to group these rows by timestamp intervals (e.g. every 32 seconds), compute aggregate functions on the...
12
by: sam_cit | last post by:
Hi Everyone, I have few questions on inline functions, when i declare a function as inline, is it for sure that the compiler would replace the function call with the actual body of the function?...
3
by: klappnase | last post by:
Hi all, yesterday I installed Python-2.5 and python-2.4.4 on my windows2k box. When trying to use os.path.exists() to detect which drives are present on the system I noticed that these behave...
4
by: python | last post by:
Bad file names, i.e. filenames the OS considers illegal, will cause functions in the os.path module to raise an error. Example: import os.path print os.path.getsize( 'c:/pytest/*.py' ) On...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.