Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
46dc4e34
Commit
46dc4e34
authored
Aug 03, 2018
by
Stefan Otte
Committed by
Berker Peksag
Aug 03, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-34329: Doc'd how to remove suffix of pathlib.Path() (GH-8655)
parent
5a953fd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
9 additions
and
3 deletions
+9
-3
Doc/library/pathlib.rst
Doc/library/pathlib.rst
+5
-1
Lib/pathlib.py
Lib/pathlib.py
+4
-2
No files found.
Doc/library/pathlib.rst
View file @
46dc4e34
...
...
@@ -559,7 +559,8 @@ Pure paths provide the following methods and properties:
.. method:: PurePath.with_suffix(suffix)
Return a new path with the :attr:`suffix` changed. If the original path
doesn't have a suffix, the new *suffix* is appended instead::
doesn't have a suffix, the new *suffix* is appended instead. If the
*suffix* is an empty string, the original suffix is removed::
>>> p = PureWindowsPath('c:/Downloads/pathlib.tar.gz')
>>> p.with_suffix('.bz2')
...
...
@@ -567,6 +568,9 @@ Pure paths provide the following methods and properties:
>>> p = PureWindowsPath('README')
>>> p.with_suffix('.txt')
PureWindowsPath('README.txt')
>>> p = PureWindowsPath('README.txt')
>>> p.with_suffix('')
PureWindowsPath('README')
.. _concrete-paths:
...
...
Lib/pathlib.py
View file @
46dc4e34
...
...
@@ -807,8 +807,10 @@ class PurePath(object):
self
.
_parts
[:
-
1
]
+
[
name
])
def
with_suffix
(
self
,
suffix
):
"""Return a new path with the file suffix changed (or added, if none)."""
# XXX if suffix is None, should the current suffix be removed?
"""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.
"""
f
=
self
.
_flavour
if
f
.
sep
in
suffix
or
f
.
altsep
and
f
.
altsep
in
suffix
:
raise
ValueError
(
"Invalid suffix %r"
%
(
suffix
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment