Python Glossary Русский

Python 3.4+pathlibterm

pathlib.PurePath.suffix

path components

The file's last extension, dot included: '.gz'. No extension — an empty string.

Syntax

PurePath(...).suffix

A hidden file without an extension, such as '.bashrc', has no suffix — the leading dot belongs to the name. To check a file type compare suffix.lower(), otherwise 'PHOTO.JPG' will not match '.jpg'.

Examples

from pathlib import PurePosixPath as P
print(P('report.tar.gz').suffix)  # → .gz
print(repr(P('.bashrc').suffix))  # → ''
print(P('PHOTO.JPG').suffix.lower() == '.jpg')  # → True

See also

Open in the full glossarydocs.python.orgReport an inaccuracy