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.exists returns False if no permission
Type: Stage:
Components: Documentation Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: akuchling Nosy List: akuchling, aminusfu, arigo, fdrake
Priority: normal Keywords: patch

Created on 2004-11-17 21:20 by aminusfu, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
libposixpath.tex.patch aminusfu, 2004-11-17 21:20 libposixpath.tex.patch
Messages (5)
msg47301 - (view) Author: Robert Brewer (aminusfu) Date: 2004-11-17 21:20
A single new sentence for os.path.exists description,
which makes it clear that it may return False even if
the path actually exists.
msg47302 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2004-12-05 06:56
Logged In: YES 
user_id=3066

This should be committed on the trunk and release24-maint
branch.
msg47303 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2004-12-20 13:00
Logged In: YES 
user_id=4771

I don't see an obvious way to do it, but shouldn't os.path.exists() try harder to return the expected answer?
msg47304 - (view) Author: Armin Rigo (arigo) * (Python committer) Date: 2004-12-20 14:53
Logged In: YES 
user_id=4771

Actually, what about the following ?

    def exists(path):
        return os.access(path, os.F_OK)

It returns True on all existing directory entries apart from broken links and links pointing within unreadable directories.

I don't see any similar nice solution for the more recent os.path.lexists()...  There are cases where the above exists() returns True but the current lexists() returns False, which is strange because lexists() is supposed to be a more permissive version of exists().
msg47305 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2006-07-29 19:57
Logged In: YES 
user_id=11375

Fred approved this patch, so I've tweaked it a little and committed it.  (rev. 
50950 on the trunk, 50951 on the release24-maint branch.)

If we want to change the underlying implementation (and hence semantics) of 
os.path.exists(), I think that should be a PEP, or at least a separate bug.
History
Date User Action Args
2022-04-11 14:56:08adminsetgithub: 41186
2004-11-17 21:20:03aminusfucreate