Issue 5318: strip, rstrip & lstrip bug (original) (raw)

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.

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>