Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(175886)

Side by Side Diff: Doc/library/os.path.rst

Issue 10395: new os.path function to extract common prefix based on path components
Patch Set: Created 6 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | Lib/ntpath.py » ('j') | Lib/ntpath.py » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 :mod:`os.path` --- Common pathname manipulations 1 :mod:`os.path` --- Common pathname manipulations
2 ================================================ 2 ================================================
3 3
4 .. module:: os.path 4 .. module:: os.path
5 :synopsis: Operations on pathnames. 5 :synopsis: Operations on pathnames.
6 6
7 .. index:: single: path; operations 7 .. index:: single: path; operations
8 8
9 This module implements some useful functions on pathnames. To read or 9 This module implements some useful functions on pathnames. To read or
10 write files see :func:`open`, and for accessing the filesystem see the 10 write files see :func:`open`, and for accessing the filesystem see the
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 platforms, this is equivalent to ``normpath(join(os.getcwd(), path))``. 45 platforms, this is equivalent to ``normpath(join(os.getcwd(), path))``.
46 46
47 47
48 .. function:: basename(path) 48 .. function:: basename(path)
49 49
50 Return the base name of pathname *path*. This is the second half of the pair 50 Return the base name of pathname *path*. This is the second half of the pair
51 returned by ``split(path)``. Note that the result of this function is differ ent 51 returned by ``split(path)``. Note that the result of this function is differ ent
52 from the Unix :program:`basename` program; where :program:`basename` for 52 from the Unix :program:`basename` program; where :program:`basename` for
53 ``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an 53 ``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an
54 empty string (``''``). 54 empty string (``''``).
55
56
57 .. function:: commonpath(paths)
58
59 Return the longest common sub-path of each pathname in the sequence
60 *paths*. Return ``None`` if *paths* contains both absolute and relative
61 pathnames, or if *paths* is empty. Unlike :func:`commonprefix`, this
62 returns a valid path.
63
64 .. versionadded:: 3.4
55 65
storchaka 2012/11/06 15:45:05 Availability: Unix, Windows. (It has not yet bee
eric.araujo 2012/11/06 16:20:32 Mac OS 9 hasn’t been supported for many versions (
storchaka 2012/11/06 16:54:49 See relpath(), samefile(), sameopenfile().
56 66
57 .. function:: commonprefix(list) 67 .. function:: commonprefix(list)
58 68
59 Return the longest path prefix (taken character-by-character) that is a prefi x 69 Return the longest path prefix (taken character-by-character) that is a prefi x
60 of all paths in *list*. If *list* is empty, return the empty string (``''`` ). 70 of all paths in *list*. If *list* is empty, return the empty string (``''`` ).
61 Note that this may return invalid paths because it works a character at a tim e. 71 Note that this may return invalid paths because it works a character at a tim e.
storchaka 2012/11/06 15:45:05 I think a reference to commonpath() will be useful
62 72
63 73
64 .. function:: dirname(path) 74 .. function:: dirname(path)
65 75
66 Return the directory name of pathname *path*. This is the first half of the 76 Return the directory name of pathname *path*. This is the first half of the
67 pair returned by ``split(path)``. 77 pair returned by ``split(path)``.
68 78
69 79
70 .. function:: exists(path) 80 .. function:: exists(path)
71 81
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 the path (such as ``r'\path\file.ext'``). For paths containing drive letter s, 330 the path (such as ``r'\path\file.ext'``). For paths containing drive letter s,
321 *unc* will always be the empty string. 331 *unc* will always be the empty string.
322 332
323 Availability: Windows. 333 Availability: Windows.
324 334
325 335
326 .. data:: supports_unicode_filenames 336 .. data:: supports_unicode_filenames
327 337
328 True if arbitrary Unicode strings can be used as file names (within limitatio ns 338 True if arbitrary Unicode strings can be used as file names (within limitatio ns
329 imposed by the file system). 339 imposed by the file system).
OLDNEW
« no previous file with comments | « no previous file | Lib/ntpath.py » ('j') | Lib/ntpath.py » ('J')

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+