PyDocs

Nav

File and Directory Access

commonprefix

os.path

function (source) Deprecated 3.15
  • commonprefix(list, /)
Deprecated since 3.15. Deprecated in favor of os.path.commonpath() for path prefixes. The os.path.commonprefix() function is being deprecated due to having a misleading name and module. The function is not safe to use for path prefixes despite being included in a module about path manipulation, meaning it is easy to accidentally introduce path traversal vulnerabilities into Python programs by using this function.
Given a list of pathnames, returns the longest common leading component
Changed in 3.6
  • 3.6: Accepts a path-like object.
1 Example
>>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
'/usr/l'

>>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
'/usr'
from the Python docs
See Also
No see-alsos for os.path/commonprefix
0 Notes
No notes for commonprefix