On 7/25/19, Chris Angelico <ros...@gmail.com> wrote: > On Fri, Jul 26, 2019 at 3:54 AM eryk sun <eryk...@gmail.com> wrote: > >> That's what I said. But the OP shows os.path.isdir(" ") == False and >> Path(" ").is_dir() == True, which is what I cannot reproduce and >> really should not be able to reproduce, unless there's a bug >> somewhere. > > Yeah but WHY is it different for an empty string?
Path.__fspath__ returns str(self), and Path.__str__ returns "." if the path is empty, i.e. there's no drive, root, or parts. I assume this is related to os.path.normpath("") == ".", which is related to os.path.normpath("spam/..") == ".". However, an empty path string isn't consistently handled as the current directory throughout the os and os.path modules. > I can well imagine that some OS/FS combinations will happily strip > spaces, thus devolving the " " case to the "" one. Windows trims trailing spaces and dots from the final component of a path, unless we use a non-normalized \\?\ path. -- https://mail.python.org/mailman/listinfo/python-list