Issue #10395: Added os.path.commonpath(). Implemented in posixpath and ntpath.

Based on patch by Rafik Draoui.
This commit is contained in:
Serhiy Storchaka 2015-03-31 15:31:53 +03:00
parent dd83bd2f9c
commit 3822093143
7 changed files with 255 additions and 5 deletions

View file

@ -66,11 +66,24 @@ the :mod:`glob` module.)
empty string (``''``).
.. function:: commonpath(paths)
Return the longest common sub-path of each pathname in the sequence
*paths*. Raise ValueError if *paths* contains both absolute and relative
pathnames, or if *paths* is empty. Unlike :func:`commonprefix`, this
returns a valid path.
Availability: Unix, Windows
.. versionadded:: 3.5
.. function:: commonprefix(list)
Return the longest path prefix (taken character-by-character) that is a prefix
of all paths in *list*. If *list* is empty, return the empty string (``''``).
Note that this may return invalid paths because it works a character at a time.
Return the longest path prefix (taken character-by-character) that is a
prefix of all paths in *list*. If *list* is empty, return the empty string
(``''``). Note that this may return invalid paths because it works a
character at a time. To obtain a valid path, see :func:`commonpath`.
.. function:: dirname(path)

View file

@ -370,6 +370,13 @@ os
* :class:`os.stat_result` now has a :attr:`~os.stat_result.st_file_attributes`
attribute on Windows. (Contributed by Ben Hoyt in :issue:`21719`.)
os.path
-------
* New :func:`~os.path.commonpath` function that extracts common path prefix.
Unlike the :func:`~os.path.commonprefix` function, it always returns a valid
patch. (Contributed by Rafik Draoui and Serhiy Storchaka in :issue:`10395`.)
pickle
------