[Tutor] lstrip removes '/' unexpectedly

Aditya Lal aditya.n.lal at gmail.com
Mon Dec 3 12:15:21 CET 2007


On Dec 3, 2007 4:29 PM, Ricardo Aráoz <ricaraoz at gmail.com> wrote:

> Danny Yoo wrote:
> >> Hello:
> >> I'm seeing some strange behavior with lstrip operating
> >> on string representations of *nix-style file paths
> >> Example:
> >>>>> s = '/home/test/'
> >>>>> s1 = s.lstrip('/home')
> >>>>> s1
> >> 'test/'   ## '/test/' was expected! '/' was unexpectedly removed
> >> Any comments or corrective measures are welcome
> >
> >
> >
> > Hi Tim,
> >
> > Here's another example to help you see what's going on:
> >
> > ##########################
> >>>> s = '/home/test/'
> >>>> s1 = s.lstrip('/ehmo')
> >>>> s1
> > 'test/'
> > ##########################
> >
> > Take a closer look at the documentation of lstrip, and you should see
> that
> > what it takes in isn't treated as a prefix: rather, it'll be treated as
> a
> > set of characters.
> >
>
> But then the real bug is why does it not strip the trailing '/' in
> 'test/' or the 'e' that is in your set?
>
>
Thats because you called lstrip() and not strip() which will strip only from
left side.

-- 
Aditya
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071203/2423d5b0/attachment.htm 


More information about the Tutor mailing list