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: strip, rstrip & lstrip bug
Type: behavior Stage:
Components: Library (Lib) Versions: Python 2.6, Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: ajaksu2, alexlc, ezio.melotti
Priority: normal Keywords:

Created on 2009-02-19 17:21 by alexlc, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
unnamed alexlc, 2009-02-19 17:42
Messages (4)
msg82480 - (view) Author: (alexlc) Date: 2009-02-19 17:21
Examples of bad behaviour:

>>> 'abacde'.lstrip('ab')
'cde'
>>> 'abaaacde'.lstrip('ab')
'cde'
>>> 'aabacde'.lstrip('aab')
'cde'
>>> 'abcede'.rstrip( 'de' )
'abc'
>>> 'abacdeaab'.strip('ab')
'cde'

Probably a few more similar to these will fail as well.

I have tested this with a fairly recent 2.5 (maybe 2.53 maybe 2.54), and
with 2.6.1. I have commented this to a friend and he recalls problems
similar to these with lstrip and rstrip a few years ago, so it might
have been an early 2.4 version or a late 2.3.

Thanks.
msg82481 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-02-19 17:25
This is not a bug:
str.strip([chars])
 ... The chars argument is not a prefix or suffix; rather, all
combinations of its values are stripped: ...

http://docs.python.org/library/stdtypes.html#str.strip
msg82483 - (view) Author: (alexlc) Date: 2009-02-19 17:42
Oh, thanks for letting me know and sorry for the trouble.
I should had read the docs more carefully. I have actually been using for a
long while the strip methods as I had described in the bug report. I was so
completely convinced about this that I didn't even thought about checking
again the docs.
I have to fix my code but I am happy nonetheless as I was kind of 'losing my
faith' in python after finding this.

Regards,
Alejandro

2009/2/19 Ezio Melotti <report@bugs.python.org>

>
> Ezio Melotti <ezio.melotti@gmail.com> added the comment:
>
> This is not a bug:
> str.strip([chars])
>  ... The chars argument is not a prefix or suffix; rather, all
> combinations of its values are stripped: ...
>
> http://docs.python.org/library/stdtypes.html#str.strip
>
> ----------
> nosy: +ezio.melotti
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <http://bugs.python.org/issue5318>
> _______________________________________
>
msg82488 - (view) Author: Daniel Diniz (ajaksu2) * (Python triager) Date: 2009-02-19 18:11
Thanks, Ezio!
History
Date User Action Args
2022-04-11 14:56:45adminsetgithub: 49568
2009-02-19 18:11:43ajaksu2setstatus: open -> closed
nosy: + ajaksu2
resolution: not a bug
messages: + msg82488
2009-02-19 17:42:05alexlcsetfiles: + unnamed
messages: + msg82483
2009-02-19 17:25:39ezio.melottisetnosy: + ezio.melotti
messages: + msg82481
2009-02-19 17:21:28alexlccreate