Vijayendra Bapte Vijayendra Bapte - 1 month ago 10
Python Question

Why does str.lstrip strips an extra character?

Python 2.6 (trunk:66714:66715M, Oct 1 2008, 18:36:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5370)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> path = "/Volumes/Users"
>>> path.lstrip('/Volume')
>>> path.lstrip('/Volumes')

I am expecting output of
should be


lstrip is character-based, it removes all characters from the left end that are in that string.

To verify this, try this:


Since / is part of the string, it is removed.

I suspect you need to use slicing instead:

if s.startsWith("/Volumes"):
    s = s[8:]

but hopefully someone with more intimate knowledge of the Python library might give you a better option.