Why exception from os.path.exists()?

Paul Moore p.f.moore at gmail.com
Thu May 31 11:30:16 EDT 2018


On 31 May 2018 at 16:11, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> On Thu, 31 May 2018 22:46:35 +1000, Chris Angelico wrote:
> [...]
>>> Most other analogous reasons *don't* generate an exception, nor is that
>>> possibility mentioned in the specification:
>>>
>>>    https://docs.python.org/3/library/os.path.html?#os.path.exists
>>>
>>> Is the behavior a bug? Shouldn't it be:
>>>
>>>    >>> os.path.exists("\0")
>>>    False
>>
>> A Unix path name cannot contain a null byte, so what you have is a
>> fundamentally invalid name. ValueError is perfectly acceptable.
>
> It should still be documented.
>
> What does it do on Windows if the path is illegal?

Returns False (confirmed with paths of '?' and ':', among others).

Paul



More information about the Python-list mailing list