ID EN
OS Path

commonprefix

Python 3.11

Return the longest string prefix (taken character-by-character) that is a prefix of all strings in list. If list is empty, return the empty string ('').

Syntax

PYTHON
os.path.commonprefix(list)

Examples

Example 1
PYTHON
>>> os.path.commonprefix(['/usr/lib', '/usr/local/lib'])
'/usr/l'

>>> os.path.commonpath(['/usr/lib', '/usr/local/lib'])
'/usr'

See Also

commonpath() path-like object