Rob,

On 03/12/2026 06:50, Jason Friedman via Python-list wrote:

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?


https://docs.python.org/3/library/os.path.html#os.path.split says:
Split the pathname path into a pair, (head, tail) ...

I see your point, but maybe because some find it easier to work with a
function which returns the same signature regardless of the input?

FWIW, same results on Linux.

Am not generally in-favor of folk who answer questions by telling us to do something else, instead of giving a direct answer. Hopefully you have that, courtesy of Jason.

In collaboration with a US-based colleague, am (gradually) constructing a PUG-talk on the `pathlib`. It is directly aimed at us 'old dogs' who learned and become (generally) comfortable with the `os` and `sys` libraries - and who may even have taken a look at `pathlib` at first splash (all those years ago!), been under-whelmed, and may not have noticed its progressive improvement since. TBA!

`pathlib` has a O-O philosophy. Accordingly, splitting paths into their components, eg separating file-name from suffix/extension/file-type is trivial and irrespective of file-system.

Recommended reading: https://docs.python.org/3/library/pathlib.html

--
Regards,
=dn

--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to