Why exception from os.path.exists()?

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Jun 1 19:54:06 EDT 2018


On Sat, 02 Jun 2018 08:50:38 +1000, Chris Angelico wrote:

> My ideal preference would be for True to mean "we know for certain that
> this exists" and False "we know for certain that this doesn't exist"

We cannot make that promise, because we might not have permission to view 
the file. Since we don't have a three-state True/False/Maybe flag, 
os.path.exists() just returns False.

> (which might be because one of its parent components doesn't exist - if
> /spam doesn't exist, then /spam/ham doesn't either, and that's just
> straight False).

And if the path is an illegal value, it also straight doesn't exist. Like 
the empty string, like "<" on Windows, like strings with too many path 
components.


-- 
Steven D'Aprano
"Ever since I learned about confirmation bias, I've been seeing
it everywhere." -- Jon Ronson




More information about the Python-list mailing list