os.readlink() doco snafu?

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

    os.readlink() doco snafu?

    English is my first language, but I doesn't be very good at it.

    I was trying to endow my symlinked python module with the ability to
    divine where it actually resides when I came across os.readlink(),
    documented at http://docs.python.org/lib/os-file-dir.html

    I'm not sure readlink() lives up to its documentation. To wit:

    $ touch bar # Create an empty file
    $ ln -s bar foo # And a symlink to it.
    $ python
    Python 2.5.1 <... Herald "the snitch" Redacted ...>
    Type "help", "copyright" , "credits" or "license" for more information.
    >>import os, os.path
    >>path = "foo"
    >>result = os.readlink(pat h)
    >>result
    'bar'
    >>abspath = os.path.join(os .path.dirname(p ath), result)
    >>os.path.isabs (abspath)
    False
    >>abspath
    'bar'

    The result makes sense, but it belies the documentation. Should I report
    this? Or is there another plausible interpretation?
  • Fredrik Lundh

    #2
    Re: os.readlink() doco snafu?

    JBW wrote:
    I'm not sure readlink() lives up to its documentation. To wit:
    >
    $ touch bar # Create an empty file
    $ ln -s bar foo # And a symlink to it.
    $ python
    Python 2.5.1 <... Herald "the snitch" Redacted ...>
    Type "help", "copyright" , "credits" or "license" for more information.
    >>>import os, os.path
    >>>path = "foo"
    >>>result = os.readlink(pat h)
    >>>result
    'bar'
    >>>abspath = os.path.join(os .path.dirname(p ath), result)
    >>>os.path.isab s(abspath)
    False
    >>>abspath
    'bar'
    >
    The result makes sense, but it belies the documentation. Should I report
    this? Or is there another plausible interpretation?
    the part about joining with dirname(path) assumes that you pass in an
    absolute path to the readlink function.

    </F>

    Comment

    • Miles

      #3
      Re: os.readlink() doco snafu?

      Fredrik Lundh wrote:
      JBW wrote:
      >I'm not sure readlink() lives up to its documentation. ...
      >The result makes sense, but it belies the documentation. Should I report
      >this? Or is there another plausible interpretation?
      >
      the part about joining with dirname(path) assumes that you pass in an
      absolute path to the readlink function.
      That documentation should probably say, "if it is relative, it may be
      converted to a pathname valid from the current working directory using
      ...."

      -Miles

      Comment

      Working...