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

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 5 years, 1 month 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') | no next file with comments »
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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
57 57
58 58
59 .. function:: basename(path) 59 .. function:: basename(path)
60 60
61 Return the base name of pathname *path*. This is the second element of the 61 Return the base name of pathname *path*. This is the second element of the
62 pair returned by passing *path* to the function :func:`split`. Note that 62 pair returned by passing *path* to the function :func:`split`. Note that
63 the result of this function is different 63 the result of this function is different
64 from the Unix :program:`basename` program; where :program:`basename` for 64 from the Unix :program:`basename` program; where :program:`basename` for
65 ``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an 65 ``'/foo/bar/'`` returns ``'bar'``, the :func:`basename` function returns an
66 empty string (``''``). 66 empty string (``''``).
67
68
69 .. function:: commonpath(paths)
70
71 Return the longest common sub-path of each pathname in the sequence
72 *paths*. Raise ValueError if *paths* contains both absolute and relative
73 pathnames, or if *paths* is empty. Unlike :func:`commonprefix`, this
74 returns a valid path.
75
76 Availability: Unix, Windows
77
78 .. versionadded:: 3.5
67 79
68 80
69 .. function:: commonprefix(list) 81 .. function:: commonprefix(list)
70 82
71 Return the longest path prefix (taken character-by-character) that is a prefi x 83 Return the longest path prefix (taken character-by-character) that is a
72 of all paths in *list*. If *list* is empty, return the empty string (``''`` ). 84 prefix of all paths in *list*. If *list* is empty, return the empty string
73 Note that this may return invalid paths because it works a character at a tim e. 85 (``''``). Note that this may return invalid paths because it works a
86 character at a time. To obtain a valid path, see :func:`commonpath`.
74 87
75 88
76 .. function:: dirname(path) 89 .. function:: dirname(path)
77 90
78 Return the directory name of pathname *path*. This is the first element of 91 Return the directory name of pathname *path*. This is the first element of
79 the pair returned by passing *path* to the function :func:`split`. 92 the pair returned by passing *path* to the function :func:`split`.
80 93
81 94
82 .. function:: exists(path) 95 .. function:: exists(path)
83 96
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 the path (such as ``r'\path\file.ext'``). For paths containing drive letter s, 354 the path (such as ``r'\path\file.ext'``). For paths containing drive letter s,
342 *unc* will always be the empty string. 355 *unc* will always be the empty string.
343 356
344 Availability: Windows. 357 Availability: Windows.
345 358
346 359
347 .. data:: supports_unicode_filenames 360 .. data:: supports_unicode_filenames
348 361
349 ``True`` if arbitrary Unicode strings can be used as file names (within limit ations 362 ``True`` if arbitrary Unicode strings can be used as file names (within limit ations
350 imposed by the file system). 363 imposed by the file system).
OLDNEW
« no previous file with comments | « no previous file | Lib/ntpath.py » ('j') | no next file with comments »

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