ID EN
OS Path

splitext

Python 3.11

Split the pathname path into a pair (root, ext) such that root + ext == path, and the extension, ext, is empty or begins with a period and contains at most one period.

Syntax

PYTHON
os.path.splitext(path)

Examples

Example 1
PYTHON
>>> splitext('bar')
('bar', '')
Example 2
PYTHON
>>> splitext('foo.bar.exe')
('foo.bar', '.exe')
>>> splitext('/foo/bar.exe')
('/foo/bar', '.exe')
Example 3
PYTHON
>>> splitext('.cshrc')
('.cshrc', '')
>>> splitext('/foo/....jpg')
('/foo/....jpg', '')

See Also

path-like object