Strange os.path.exists() behaviour

Sion Arrowsmith siona at chiark.greenend.org.uk
Thu Jul 7 09:29:20 EDT 2005


Jeff Epler  <jepler at unpythonic.net> wrote:
>Pierre wrote:
>> Python 2.4 (#60, Nov 30 2004, 11:49:19) [MSC v.1310 32 bit (Intel)] on wi=
>n32
>                                                                       ^^^^=
>^^^
>Here's the bug.  You're using Windows.  It's a filesystem, but not as we kn=
>ow it...
> [ ... ]
>As you can see, not only does Windows think that "exist...." exists, but it=
> can
>successfully "type" its contents too!

The "reason" for this behaviour is that the concept of a file
extension is firmly embedded in the operating system. exists is a
file with no extension, as is exists. (no, it doesn't make a
distinction between "no extension" and "an empty extension").
>From there it's not too great a leap of induction to suppose that
exists.... is the same file called exists with no extension. It's
not unlike being able to stick an arbitrary number of /s onto the
end of a directory name on a sane OS/filesystem.

-- 
\S -- siona at chiark.greenend.org.uk -- http://www.chaos.org.uk/~sion/
  ___  |  "Frankly I have no feelings towards penguins one way or the other"
  \X/  |    -- Arthur C. Clarke
   her nu becomeþ se bera eadward ofdun hlæddre heafdes bæce bump bump bump



More information about the Python-list mailing list