Bug or feature? Slash in os and os.path

Christian Tismer tismer at appliedbiometrics.com
Wed May 19 16:24:15 EDT 1999


Tim Peters wrote:
> 
> [Christian Tismer]
> > What is the desired behavior of os.listdir, os.path.listdir
> > and os.path.exists?

[examples]

> Yes, it sucks, but I don't know how to fix it.  The behaviors of exists,
> isdir and isfile are inherited from os.stat, and Microsoft's implementation
> of the latter is what's picky about the trailing slash.

Well, I recently submitted a patch which dealt with similar
inconsistencies. The "error" implementation of MS' libc is
inconsistent with POSIX, since there is a bad mapping
between DOS error codes and Posix error codes.

I had to replace it by a special Windows function, and now
os.listdir("jibbetnich") is no longer telling about
"no such process", but says correctly
"no such path" or so.

I fear I will have to do more of these: special casing
libc deficiencies for Windows.

> Python returns the same, because the above is what libc is telling it.  So
> you're tempted to conclude "ok, under Windows, never ever put a trailing
> slash on the argument".  But then the output of the last two lines:
> 
> d: doesn't exist; code -1.
> d:/ exists.
> 
> So sometimes you *have* to use a trailing slash!  Brrrrrr.  Consistency is
> impossible.

Maybe consistency is possible so far, that a trailing slash is
allowed when listdir can read the directory.

> Believe UNC mount points (like \\machine\share\) act similarly to raw drive
> letters here, requiring a trailing slash to succeed.
> 
> OTOH, the native Win32 GetFileAttributes works fine:

Yes, here we are. We must change them all to native Win32
functions. All the rest is crappy.

ciao - and thanks for the work - chris

-- 
Christian Tismer             :^)   <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH      :     Have a break! Take a ride on Python's
Kaiserin-Augusta-Allee 101   :    *Starship* http://starship.python.net
10553 Berlin                 :     PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint       E182 71C7 1A9D 66E9 9D15  D3CC D4D7 93E2 1FAE F6DF
     we're tired of banana software - shipped green, ripens at home




More information about the Python-list mailing list