MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / commonprefix

Function commonprefix

tools/python-3.11.9-amd64/Lib/genericpath.py:69–83  ·  view source on GitHub ↗

Given a list of pathnames, returns the longest common leading component

(m)

Source from the content-addressed store, hash-verified

67
68# Return the longest prefix of all list elements.
69def commonprefix(m):
70 "Given a list of pathnames, returns the longest common leading component"
71 if not m: return ''
72 # Some people pass in a list of pathname parts to operate in an OS-agnostic
73 # fashion; don't try to translate in that case as that's an abuse of the
74 # API and they are already doing what they need to be OS-agnostic and so
75 # they most likely won't be using an os.PathLike object in the sublists.
76 if not isinstance(m[0], (list, tuple)):
77 m = tuple(map(os.fspath, m))
78 s1 = min(m)
79 s2 = max(m)
80 for i, c in enumerate(s1):
81 if c != s2[i]:
82 return s1[:i]
83 return s1
84
85# Are two stat buffers (obtained from stat, fstat or lstat)
86# describing the same file?

Callers 4

_common_shorten_reprFunction · 0.90
regex_opt_innerFunction · 0.90
_get_index_urlMethod · 0.90
relpathFunction · 0.85

Calls 5

tupleClass · 0.85
minFunction · 0.85
maxFunction · 0.85
enumerateFunction · 0.85
mapFunction · 0.50

Tested by

no test coverage detected