[Tutor] lstrip removes '/' unexpectedly

Kent Johnson kent37 at tds.net
Fri Nov 30 20:31:40 CET 2007


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
> Any comments or corrective measures are welcome

I usually do something like
if s.startswith('/home'):
   s = s[5:]

or
   s = s[len('/home'):]

Kent


More information about the Tutor mailing list