Why exception from os.path.exists()?
Steven D'Aprano
steve+comp.lang.python at pearwood.info
Sat Jun 2 07:05:28 EDT 2018
On Sat, 02 Jun 2018 01:51:07 +0000, Grant Edwards wrote:
> What about the case where somebody calls
>
> os.path.exists("/tmp/foo\x00bar")
>
> If /tmp/foo exists should it return True?
That depends on whether /tmp/foo is a directory containing a file \0bar
or not. Since that is not a legal file name on POSIX systems, it should
return False. On Windows, I don't know whether such a file could exist or
not.
> That's what would happen if
> you passed that string directly to the libc call.
Fortunately, as Python programmers, we're not passing the string directly
to the libc call. We're passing a Python string to a Python function.
Nor are we receiving the result directly back from the libc call, since
it neither returns bool objects, nor raises exceptions on error.
--
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