Why exception from os.path.exists()?

MRAB python at mrabarnett.plus.com
Thu May 31 10:51:06 EDT 2018


On 2018-05-31 14:38, Marko Rauhamaa wrote:
> Chris Angelico <rosuav at gmail.com>:
>> Do you have an actual use-case where it is correct for an invalid path
>> to be treated as not existing?
> 
> Note that os.path.exists() returns False for other types of errors
> including:
> 
>   * File might exist but you have no access rights
> 
>   * The pathname is too long for the file system
> 
>   * The pathname is a broken symbolic link
> 
>   * The pathname is a circular symbolic link
> 
>   * The hard disk ball bearings are chipped
> 
> I'm not aware of any other kind of a string argument that would trigger
> an exception except the presence of a NUL byte.
> 
> The reason for the different treatment is that the former errors are
> caught by the kernel and converted to False by os.path.exists(). The NUL
> byte check is carried out by Python's standard library.
> 
On Windows, the path '<' is invalid, but os.path.exists('<') returns 
False, not an error.

The path '' is also invalid, but os.path.exists('') returns False, not 
an error.

I don't see why '\0' should behave any differently.



More information about the Python-list mailing list