Discussion:
[issue24445] rstrip strips what it doesn't have to
o1da
2015-06-13 13:29:53 UTC
Permalink
New submission from o1da:

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.

----------
messages: 245311
nosy: o1da
priority: normal
severity: normal
status: open
title: rstrip strips what it doesn't have to
versions: Python 2.7

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________
Patrick Maupin
2015-06-13 13:46:38 UTC
Permalink
Patrick Maupin added the comment:

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

----------
nosy: +Patrick Maupin

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________
Patrick Maupin
2015-06-13 13:47:55 UTC
Permalink
Patrick Maupin added the comment:

Example
text = 'test1/1.jp2'
text.rstrip('.2jp')
'test1/1'

----------

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________
o1da
2015-06-13 13:51:58 UTC
Permalink
o1da added the comment:

Ok, thank you. I thought it trims whole sequence or nothing.

----------
status: open -> closed

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________
Martin Panter
2015-06-13 14:00:13 UTC
Permalink
Martin Panter added the comment:

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.

----------
nosy: +vadmium

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________
Zachary Ware
2015-06-13 18:30:36 UTC
Permalink
Changes by Zachary Ware <***@gmail.com>:


----------
resolution: -> not a bug
stage: -> resolved

_______________________________________
Python tracker <***@bugs.python.org>
<http://bugs.python.org/issue24445>
_______________________________________

Loading...