Issue 6049: str.strip() and " behaviour expected? (original) (raw)

Hey guys,

is the following behaviour expected? I don't really think so...

$ python Python 3.0.1 (r301:69597, Feb 14 2009, 19:03:52) [GCC 4.0.1 (Apple Inc. build 5490)] on darwin Type "help", "copyright", "credits" or "license" for more information.

s = ' "Peter"' s ' "Peter"' s.strip() '"Peter"' s.strip('"') ' "Peter' s.strip('"') ' "Peter' s.strip('""') ' "Peter'

s.strip() '"Peter"' s.strip().strip('"') 'Peter' s.strip('"').strip() '"Peter'

Yes, it is expected. When you call .strip() without args it strips the whitespaces, when you call with an arg it strips only what you specified. In this example:

s.strip('"') ' "Peter' the left " is not removed because there's a space in between, in this example: s.strip().strip('"') 'Peter' you first remove the space and then the two ".