diff options
author | Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> | 2020-04-19 15:29:49 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-19 15:29:49 (GMT) |
commit | 8aea4b3605059e243f1827d9328d6fc8d698c0a7 (patch) | |
tree | c77751052337cc6b87f227905c8bb5b447157d2d /Doc/library/pathlib.rst | |
parent | c8f1715283ec51822fb37a702bf253cbac1af276 (diff) | |
download | cpython-8aea4b3605059e243f1827d9328d6fc8d698c0a7.zip cpython-8aea4b3605059e243f1827d9328d6fc8d698c0a7.tar.gz cpython-8aea4b3605059e243f1827d9328d6fc8d698c0a7.tar.bz2 |
bpo-40148: Add PurePath.with_stem() (GH-19295)
Add PurePath.with_stem()
Diffstat (limited to 'Doc/library/pathlib.rst')
-rw-r--r-- | Doc/library/pathlib.rst | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/Doc/library/pathlib.rst b/Doc/library/pathlib.rst index d4329e7..dead49b 100644 --- a/Doc/library/pathlib.rst +++ b/Doc/library/pathlib.rst @@ -571,6 +571,30 @@ Pure paths provide the following methods and properties: ValueError: PureWindowsPath('c:/') has an empty name +.. method:: PurePath.with_stem(stem) + + Return a new path with the :attr:`stem` changed. If the original path + doesn't have a name, ValueError is raised:: + + >>> p = PureWindowsPath('c:/Downloads/draft.txt') + >>> p.with_stem('final') + PureWindowsPath('c:/Downloads/final.txt') + >>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz') + >>> p.with_stem('lib') + PureWindowsPath('c:/Downloads/lib.gz') + >>> p = PureWindowsPath('c:/') + >>> p.with_stem('') + Traceback (most recent call last): + File "<stdin>", line 1, in <module> + File "/home/antoine/cpython/default/Lib/pathlib.py", line 861, in with_stem + return self.with_name(stem + self.suffix) + File "/home/antoine/cpython/default/Lib/pathlib.py", line 851, in with_name + raise ValueError("%r has an empty name" % (self,)) + ValueError: PureWindowsPath('c:/') has an empty name + + .. versionadded:: 3.9 + + .. method:: PurePath.with_suffix(suffix) Return a new path with the :attr:`suffix` changed. If the original path |