Why exception from os.path.exists()?

Grant Edwards grant.b.edwards at gmail.com
Fri Jun 1 21:51:07 EDT 2018


On 2018-06-01, Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> But since "\0" is the correct type (a string), and the fact that it 
> happens to be illegal on POSIX is a platform-dependent detail of no more 
> importance than the fact that "?" is illegal on Windows, it should be 
> treated as any other platform-dependent illegal file and return False.

That sounds reasonable.

What about the case where somebody calls

os.path.exists("/tmp/foo\x00bar")

If /tmp/foo exists should it return True?  That's what would happen if
you passed that string directly to the libc call.

--
Grant






More information about the Python-list mailing list