Tim Johnson 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
>   

Hi Tim,

I believe you've misunderstood how lstrip works.  The sequence passed to 
the lstrip() method is a list of characters to remove from the string, 
not a string to match as a unit:

 >>> s1 = 'aaaaabbbbbcccccc'
 >>> s1.lstrip( 'ab' )
'cccccc'

In your example, since the '/' character is in the list to strip, the 
second slash goes with it.

Hope that helps,
e.


> Any comments or corrective measures are welcome
> thanks
> Tim
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to