Op 2/12/2026 om 18:16 schreef Rob Cliffe via Python-list:
This is all on Windows.
I was surprised to discover that
os.path.split(".")
returns
('', '.')
rather than
('.', '')
i.e. the dot is treated as (part of) a file name rather than a
directory name.
After all, "." is not a valid file name (though it could be part of a
file name) but IS a valid directory name.
Is there a good reason for this?
I don't think os.path.split() takes into account "." being a valid
directory name but not a valid file name. It's perfectly fine to use
os.path.split() on a path that consists solely of directory names, so
"." is perfectly fine. I think os.path.split() just follows what its
documentation says:
"Split the pathname path into a pair, (head, tail) where tail is the
last pathname component and head is everything leading up to that."
In the path ".", "." is the last part (which is put in tail), and there
is nothing leading up to it (so head becomes the empty string). It seems
to me the observed behavior matches the description of the function. I
think that's all there is to it. Note that the documentation never talks
about directories and files, it's all about pathname components in general.
--
"Honest criticism is hard to take, particularly from a relative, a friend,
an acquaintance, or a stranger."
-- Franklin P. Jones
--
https://mail.python.org/mailman3//lists/python-list.python.org