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.
(self, suffix)
| 428 | return self.with_name(stem + suffix) |
| 429 | |
| 430 | def with_suffix(self, suffix): |
| 431 | """Return a new path with the file suffix changed. If the path |
| 432 | has no suffix, add given suffix. If the given suffix is an empty |
| 433 | string, remove the suffix from the path. |
| 434 | """ |
| 435 | stem = self.stem |
| 436 | if not stem: |
| 437 | # If the stem is empty, we can't make the suffix non-empty. |
| 438 | raise ValueError(f"{self!r} has an empty name") |
| 439 | elif suffix and not suffix.startswith('.'): |
| 440 | raise ValueError(f"Invalid suffix {suffix!r}") |
| 441 | else: |
| 442 | return self.with_name(stem + suffix) |
| 443 | |
| 444 | @property |
| 445 | def stem(self): |