This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: os.path symlink docs missing
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: works for me
Dependencies: Superseder:
Assigned To: docs@python Nosy List: dabrahams, docs@python, larry, r.david.murray
Priority: normal Keywords:

Created on 2012-08-01 19:00 by dabrahams, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (7)
msg167163 - (view) Author: Dave Abrahams (dabrahams) Date: 2012-08-01 19:00
the docs for os.path don't mention the following facts which I think are important (in fact I assumed the facts would be the reverse):

os.path.realpath(l) works when l is a broken symbolic link, returning the path to the (missing) target

os.path.readlink(l) causes an error when l is a broken symbolic link.
msg167439 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2012-08-04 20:56
The first of those acts as I would expect: os.path.realpath is operating only on the path, so if the last element is a symbolic link it doesn't have any reason to look for the target of that link.

The second one does seem less intuitive.

I'm not sure the first case is worth a patch...I'd have to see a suggested wording.  The second probably is, assuming it is not in fact a bug.
msg167463 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-08-05 00:36
I just tried it, and os.readlink('/tmp/broken-symlink') worked fine.  What OS are you using?
msg167466 - (view) Author: Dave Abrahams (dabrahams) Date: 2012-08-05 00:42
MacOS 10.7
msg167467 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-08-05 00:54
What does the following script print out?

import os

os.chdir('/tmp')
os.symlink('--success--', 'foo')
print("this should print --success-- :")
print(os.readlink('foo'))
os.unlink('foo')
msg167510 - (view) Author: Dave Abrahams (dabrahams) Date: 2012-08-05 19:02
on Sat Aug 04 2012, Larry Hastings <report-AT-bugs.python.org> wrote:

> Larry Hastings added the comment:
>
> What does the following script print out?
>
> import os
>
> os.chdir('/tmp')
> os.symlink('--success--', 'foo')
> print("this should print --success-- :")
> print(os.readlink('foo'))
> os.unlink('foo')

--8<---------------cut here---------------start------------->8---
this should print --success-- :
--success--
--8<---------------cut here---------------end--------------->8---

So, I guess I don't know what was causing the symptom I observed.
msg167513 - (view) Author: Larry Hastings (larry) * (Python committer) Date: 2012-08-05 21:19
Since everything is working fine, and the documentation arguably needs no update, I'm closing this.
History
Date User Action Args
2022-04-11 14:57:33adminsetgithub: 59736
2012-08-05 21:19:07larrysetstatus: open -> closed
resolution: works for me
messages: + msg167513

stage: resolved
2012-08-05 19:02:57dabrahamssetmessages: + msg167510
2012-08-05 00:54:38larrysetmessages: + msg167467
2012-08-05 00:42:33dabrahamssetmessages: + msg167466
2012-08-05 00:36:23larrysetmessages: + msg167463
2012-08-04 20:56:34r.david.murraysetnosy: + r.david.murray, larry
messages: + msg167439
2012-08-01 19:00:02dabrahamscreate