473,695 Members | 1,926 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 1948
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******@hotmai l.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
6177
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 get the path ...and save it, (in a cookie or in MySQL ). $ReturnUrl = $_SERVER.'?'.$_SERVER;
1
6952
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 calculations. One of these calculations is rather complex, and could not be implemented properly using just nested IIF statements or anything similar, so was coded using VBA (in the VBE) as a function. This calculation is included in a query in the...
12
4033
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 pathname component and head is everything leading up to that. The tail part will never contain a slash; if path ends in a slash, tail will be empty. If there is no slash in path, head will be empty. If
6
1919
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 look at the query below. There is a btree index on both m.account_id and a.account_id. Query (1) does not use the index on the messages table, instead opting for a full table scan, thus killing performance. The messages table can contain...
9
13731
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: Could not find a part of the path "D:\". The full path is "D:\hshome\clinton\test.gotchasoft.com\verify" The web is running using impersonation as a user on the local machine.
2
720
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 columns, and ultimately feed the result into a graph-drawing web thingy. I'm trying a few different ways to get what seems to be the same data, and seeing some odd behavior from the query planner. The table looks like this:
12
676
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? or is it a call taken by compiler? Second, i see that it is same as what Macro's used to do for c, if so what is the advantage for going in for inline functions than to Macros?
3
1587
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 differently: Python 2.4.4 (#71, Oct 18 2006, 08:34:43) on win32 Type "copyright", "credits" or "license()" for more information.
4
3248
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 Windows XP using Python 2.5.2 I get the following traceback:
0
8623
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8565
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
8839
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6488
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5837
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4339
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2269
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1971
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.