PyDocs

Nav

File and Directory Access

PurePath.with_suffix

pathlib

method of PurePath (source)
  • PurePath.with_suffix(suffix)
Return a new path with the file suffix changed.  If the path
has no suffix, add given suffix.  If the given suffix is an empty
string, remove the suffix from the path.
Changed in 3.14
  • 3.14: A single dot (”.”) is considered a valid suffix. In previous versions, ValueError is raised if a single dot is supplied.
1 Example
>>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
>>> p.with_suffix('.bz2')
PureWindowsPath('c:/Downloads/pathlib.tar.bz2')
>>> p = PureWindowsPath('README')
>>> p.with_suffix('.txt')
PureWindowsPath('README.txt')
>>> p = PureWindowsPath('README.txt')
>>> p.with_suffix('')
PureWindowsPath('README')
from the Python docs
See Also
No see-alsos for pathlib/PurePath.with_suffix
0 Notes
No notes for PurePath.with_suffix