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: string.strip behaves strangly
Type: behavior Stage:
Components: Interpreter Core Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: dwjang, ezio.melotti, loewis
Priority: normal Keywords:

Created on 2009-03-08 05:28 by dwjang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg83300 - (view) Author: Dongwook Jang (dwjang) Date: 2009-03-08 05:28
Python 2.4.2 (#1, Mar  4 2008, 22:56:43)
[GCC 3.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> temp = "a/b/c"
>>> temp.strip("a")
'/b/c'
>>> temp.strip("a/")
'b/c'
>>> temp.strip("a/b")
'c'
>>> temp.strip("a/b/")
'c'
>>>


So, in the second command from the last, I expected '/c' but it gives
only 'c'.
Why? Is it a bug or a feature that I don't understand?

Thanks,
DW
msg83302 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2009-03-08 05:32
http://docs.python.org/library/string.html#string.strip

string.strip(s[, chars])

    Return a copy of the string with leading and trailing characters
removed. If chars is omitted or None, whitespace characters are removed.
If given and not None, chars must be a string; the characters in the
string **will be stripped from the both ends** of the string this method
is called on.
msg83306 - (view) Author: Martin v. Löwis (loewis) * (Python committer) Date: 2009-03-08 08:08
It's a feature you don't understand. .strip() doesn't expect the
substring to be stripped, but a list of characters. Since the strip
characters contain /, all leading a,/,b characters get stripped (in any
order:

py> "////aaab/csdfhkab///c".strip("a/b")
'csdfhkab///c'
History
Date User Action Args
2022-04-11 14:56:46adminsetgithub: 49689
2009-03-08 08:08:59loewislinkissue5440 dependencies
2009-03-08 08:08:21loewissetstatus: open -> closed
nosy: + loewis
resolution: not a bug
messages: + msg83306
2009-03-08 05:32:10ezio.melottisetnosy: + ezio.melotti
messages: + msg83302
2009-03-08 05:28:11dwjangcreate