os.path query functions behavior incorrect?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Beman Dawes

    #1

    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):
    [color=blue][color=green][color=darkred]
    >>> import os
    >>> print os.path.exists( "c:\\")[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> print os.path.isdir(" c:\\")[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> print os.path.isdir(" c:\\boost")[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> print os.path.isdir(" c:\\foo")[/color][/color][/color]
    False

    OK, that meets my expectations. But now:
    [color=blue][color=green][color=darkred]
    >>> print os.path.exists( "a:\\")[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>> print os.path.isdir(" a:\\")[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>> print os.path.exists( "d:\\")[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> print os.path.isdir(" d:\\")[/color][/color][/color]
    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


  • Mike Rovner

    #2
    Re: os.path query functions behavior incorrect?

    Beman Dawes wrote:[color=blue]
    > So are these os.path functions specified and implemented incorrectly? Should
    > they instead throw exceptions for the above examples?[/color]

    Works for me. (Win XP SP2, Py 2.4, only have c and d drives)
    [color=blue][color=green][color=darkred]
    >>> os.path.exists( 'd:\\')[/color][/color][/color]
    True[color=blue][color=green][color=darkred]
    >>> os.path.exists( 'e:\\')[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>> os.path.exists( 'a:\\')[/color][/color][/color]
    False[color=blue][color=green][color=darkred]
    >>>[/color][/color][/color]

    Comment

    • wittempj@hotmail.com

      #3
      Re: os.path query functions behavior incorrect?

      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.[color=blue][color=green][color=darkred]
      >>> import os.path
      >>> os.path.exists( '/blah')[/color][/color][/color]
      False[color=blue][color=green][color=darkred]
      >>> os.path.isdir('/blah')[/color][/color][/color]
      False[color=blue][color=green][color=darkred]
      >>> os.path.isdir('/home/martin')[/color][/color][/color]
      True[color=blue][color=green][color=darkred]
      >>> os.path.exists( '/home/martin')[/color][/color][/color]
      True[color=blue][color=green][color=darkred]
      >>>[/color][/color][/color]

      Comment

      • Georg Brandl

        #4
        Re: os.path query functions behavior incorrect?

        wittempj@hotmai l.com wrote:[color=blue]
        > 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.[color=green][color=darkred]
        >>>> import os.path
        >>>> os.path.exists( '/blah')[/color][/color]
        > False[color=green][color=darkred]
        >>>> os.path.isdir('/blah')[/color][/color]
        > False[color=green][color=darkred]
        >>>> os.path.isdir('/home/martin')[/color][/color]
        > True[color=green][color=darkred]
        >>>> os.path.exists( '/home/martin')[/color][/color]
        > True[color=green][color=darkred]
        >>>>[/color][/color][/color]

        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

        Comment

        • Simon Percivall

          #5
          Re: os.path query functions behavior incorrect?

          > These to me are I/O errors that should result in an exception.[color=blue]
          > Doing a command line dir a:\ reports "The system cannot find
          > the path specified."[/color]

          The functions use the underlying C library, and in this case, the
          result is not guaranteed by the standard.

          Comment

          Working...