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: Weird S.rstrip() result
Type: behavior Stage:
Components: Versions: Python 3.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: SzieberthAdam, pitrou
Priority: normal Keywords:

Created on 2014-10-31 14:25 by SzieberthAdam, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg230343 - (view) Author: Szieberth Ádám (SzieberthAdam) Date: 2014-10-31 14:25
I just faced the following bug (v3.4.2):

>>> t1 = '#5 amarg (Concession)'
>>> t2 = '#6 ironman (Concession)'
>>> s = ' (Concession)'
>>> t1.rstrip(s)
'#5 amarg'
>>> t2.rstrip(s)
'#6 ironma'
>>> t1[:-len(s)]
'#5 amarg'
>>> t2[:-len(s)]
'#6 ironman'
msg230348 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-10-31 14:58
It may be unexpected, but it's not a bug. From the documentation:

"""Return a copy of the string with trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. **The chars argument is not a suffix; rather, all combinations of its values are stripped**.""" (emphasis mine)

https://docs.python.org/3/library/stdtypes.html#str.rstrip

(if you wonder why that is, think about e.g. the use case of stripping certain whitespace characters: s.rstrip(" \t"))
History
Date User Action Args
2022-04-11 14:58:09adminsetgithub: 66963
2014-10-31 14:58:35pitrousetstatus: open -> closed

nosy: + pitrou
messages: + msg230348

resolution: not a bug
2014-10-31 14:25:09SzieberthAdamcreate