Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

string.strip behaves strangly #49689

Closed
dwjang mannequin opened this issue Mar 8, 2009 · 3 comments
Closed

string.strip behaves strangly #49689

dwjang mannequin opened this issue Mar 8, 2009 · 3 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@dwjang
Copy link
Mannequin

dwjang mannequin commented Mar 8, 2009

BPO 5439
Nosy @loewis, @ezio-melotti

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2009-03-08.08:08:21.033>
created_at = <Date 2009-03-08.05:28:10.942>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'string.strip behaves strangly'
updated_at = <Date 2009-03-08.08:08:20.996>
user = 'https://bugs.python.org/dwjang'

bugs.python.org fields:

activity = <Date 2009-03-08.08:08:20.996>
actor = 'loewis'
assignee = 'none'
closed = True
closed_date = <Date 2009-03-08.08:08:21.033>
closer = 'loewis'
components = ['Interpreter Core']
creation = <Date 2009-03-08.05:28:10.942>
creator = 'dwjang'
dependencies = []
files = []
hgrepos = []
issue_num = 5439
keywords = []
message_count = 3.0
messages = ['83300', '83302', '83306']
nosy_count = 3.0
nosy_names = ['loewis', 'ezio.melotti', 'dwjang']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue5439'
versions = ['Python 2.4']

@dwjang
Copy link
Mannequin Author

dwjang mannequin commented Mar 8, 2009

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

@dwjang dwjang mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Mar 8, 2009
@ezio-melotti
Copy link
Member

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.

@loewis
Copy link
Mannequin

loewis mannequin commented Mar 8, 2009

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'

@loewis loewis mannequin closed this as completed Mar 8, 2009
@loewis loewis mannequin added the invalid label Mar 8, 2009
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant