Difference between os.path.isdir and Path.is_dir

Kirill Balunov kirillbalunov at gmail.com
Thu Jul 25 15:02:27 EDT 2019


чт, 25 июл. 2019 г. в 20:28, eryk sun <eryksun at gmail.com>:

> On 7/25/19, Kirill Balunov <kirillbalunov at gmail.com> wrote:
> >
> >>>> import os
> >>>> from pathlib import Path
> >>>> dummy = " "   # or "" or "     "
> >>>> os.path.isdir(dummy)
> > False
> >>>> Path(dummy).is_dir()
> > True
>
> I can't reproduce the above result in either Linux or Windows. The
> results should only be different for an empty path string, since
> Path('') is the same as Path('.'). The results should be the same for
> Path(" "), depending on whether a directory named " " exists (normally
> not allowed in Windows, but Linux allows it).
>
>
Heh, something fishy is going on. I also can't reproduce that behavior
(with " " and "   ") at home comp on Windows 10 Python 3.7.4. Tomorrow I'll
check again at work and let you know. I apologize in advance. The main
problem arose огые with an empty line, but then I checked with " " and
apparently made a mistake somewhere.

with kind regards,
-gdg



More information about the Python-list mailing list