This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: rstrip strips what it doesn't have to
Type: Stage: resolved
Components: Versions: Python 2.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Patrick Maupin, martin.panter, o1da
Priority: normal Keywords:

Created on 2015-06-13 13:29 by o1da, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg245311 - (view) Author: o1da (o1da) Date: 2015-06-13 13:29
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> text = 'test1/1.jp2'
>>> text.rstrip('.jp2')
'test1/1'
>>> text = 'test1.jp2'
>>> text.rstrip('.jp2')
'test1'
>>> text = 'test1/2.jp2'
>>> text.rstrip('.jp2')
'test1/'
>>> 

Why the rstrip function stripped '2' from the last example? I think that it is a bug.
msg245312 - (view) Author: Patrick Maupin (Patrick Maupin) * Date: 2015-06-13 13:46
I think you misunderstand rstrip -- it works from the right, and checks to see if the right-most character is in the string you have given it.  As long as it is, then it will remove the character and loop
msg245313 - (view) Author: Patrick Maupin (Patrick Maupin) * Date: 2015-06-13 13:47
Example

>>> text = 'test1/1.jp2'
>>> text.rstrip('.2jp')
'test1/1'
msg245314 - (view) Author: o1da (o1da) Date: 2015-06-13 13:51
Ok, thank you. I thought it trims whole sequence or nothing.
msg245315 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-06-13 14:00
The 3.5 documentation of str.strip() was recently modified in Issue 24204 due to this kind of misunderstanding. Perhaps other versions should be modified as well, or the str.l/rstrip() methods, or the bytes() and bytearray() methods. See also Issue 23560 proposing to group the documentation of these methods together.
History
Date User Action Args
2022-04-11 14:58:18adminsetgithub: 68633
2015-06-13 18:30:36zach.waresetresolution: not a bug
stage: resolved
2015-06-13 14:00:13martin.pantersetnosy: + martin.panter
messages: + msg245315
2015-06-13 13:51:58o1dasetstatus: open -> closed

messages: + msg245314
2015-06-13 13:47:55Patrick Maupinsetmessages: + msg245313
2015-06-13 13:46:38Patrick Maupinsetnosy: + Patrick Maupin
messages: + msg245312
2015-06-13 13:29:53o1dacreate