Problem with string parsing

Peter L Hansen peter at engcorp.com
Wed Oct 6 03:51:03 CEST 2004


wes weston wrote:
> Mike,
>    Note that after the appropriate if:
> 
>  >>> '1_mature_dt=10-May-2002'[len('1_mature_dt='):]
> '10-May-2002'

Though I would guess that the following is closer to
what was actually thought by the OP to be the behaviour of
.lstrip():

def lstripsub(s, sub):
     if s.startswith(sub):
         return s[len(sub):]
     else:
         return s

 >>> s = '1_mature_dt=10-May-2002'
 >>> lstripsub(s, '1_mature_dt=')
'10-May-2002'

-Peter



More information about the Python-list mailing list