02.06.18 03:05, Chris Angelico пише:
The permissions error is reported differently by stat, but then
exists() just says "oh that's an OS error so we're going to say it
doesn't exist". If you truly want the reliable form of os.path.exists,
it would be this:
try:
os.stat(path)
return True
except FileNotFoundError:
return False
Anything that ISN'T "this file exists" or "this file doesn't exist"
will be signalled with an exception.
And this is how pathlib.Path.exists() was implemented. But for
os.path.exists() we are limited by backward compatibility.
--
https://mail.python.org/mailman/listinfo/python-list