From: Jason Friedman on
$ python
Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
[GCC 4.4.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> "x.vsd-dir".rstrip("-dir")
'x.vs'

I expected 'x.vsd' as a return value.
From: Thomas Jollans on
On 07/16/2010 06:58 PM, Jason Friedman wrote:
> $ python
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> "x.vsd-dir".rstrip("-dir")
> 'x.vs'
>
> I expected 'x.vsd' as a return value.

>>> "x-vsd-dir".rstrip("-dir")
'x-vs'
>>> "x-vsd-dir".rstrip("123id-r456")
'x-vs'
>>> "x-vsd-dir".rstrip("-di")
'x-vsd-dir'
>>> "fooabc".rstrip("bca")
'foo'
>>>

http://docs.python.org/py3k/library/stdtypes.html#str.rstrip ::

""" The chars argument is not a suffix; rather, all combinations of its
values are stripped: """



From: Ken Watford on
On Fri, Jul 16, 2010 at 12:58 PM, Jason Friedman <jason(a)powerpull.net> wrote:
> $ python
> Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> "x.vsd-dir".rstrip("-dir")
> 'x.vs'
>
> I expected 'x.vsd' as a return value.
> --
> http://mail.python.org/mailman/listinfo/python-list
>

rstrip strips a given set of characters, not a specific string. '-dir'
contains d, so the trailing d is also stripped.
From: MRAB on
Jason Friedman wrote:
> $ python
> Python 2.6.4 (r264:75706, Dec 7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> "x.vsd-dir".rstrip("-dir")
> 'x.vs'
>
> I expected 'x.vsd' as a return value.

..strip, .lstrip and .rstrip treat their argument like a set of
characters and remove any of those characters from the end(s) of the
string.

In your example it's removing any "-", "d", "i" or "r" from the
right-hand end of "x.vsd-dir", leaving "x.vs", like this:

result = "x.vsd-dir"
characters = "-dir"
while result and result[-1] in characters:
result = result[ : -1]
From: Novocastrian_Nomad on
On Jul 16, 10:58 am, Jason Friedman <ja...(a)powerpull.net> wrote:
> $ python
> Python 2.6.4 (r264:75706, Dec  7 2009, 18:43:55)
> [GCC 4.4.1] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>> "x.vsd-dir".rstrip("-dir")
>
> 'x.vs'
>
> I expected 'x.vsd' as a return value.

One way to achieve the desired result:
'x.vsd-dir'.split('-')[0]