[Python-ideas] os.path.commonprefix: Yes that old chestnut.

random832 at fastmail.us random832 at fastmail.us
Tue Mar 24 14:41:51 CET 2015


On Tue, Mar 24, 2015, at 07:56, Paul Moore wrote:
> For example, common_prefix('a/b/file.c', 'a/b/file.c'). The common
> prefix is obviously 'a/b/file.c' - but I can imagine people *actually*
> wanting the common *directory* containing both files. But taken
> literally, that's only possible if you check the filesystem, so it
> would no longer be a PurePath operation.

Or you could _always_ reject the last component. That is, even if
"file.c" is a directory, return the directory it is in rather than
itself.

Does parts differentiate between "a/b/c" and "a/b/c/"? There are
certainly contexts where real filesystems differentiate between them
(symlinks, for example).


More information about the Python-ideas mailing list