bizarre behavior using .lstrip

Peter Hansen peter at engcorp.com
Sat Sep 20 15:47:34 EDT 2003


Terry Reedy wrote:
> 
> "Peter Hansen" <peter at engcorp.com> wrote in message
> news:3F6B9B44.9EAD3CF9 at engcorp.com...
> > > Does this make any sense at all?  where did the lead c in conn_fee
> go?
> >
> > Based on the behaviour you describe, I would assume lstrip()
> > removes, starting at the beginning of the string, all characters
> > which are *anywhere* in the argument string you give it, until
> > it encounters a character not in that string, at which point it
> > stops.
> 
> Good call:  from Lib Ref 2.2.6.1 String Methods
> 
> lstrip( [chars])
> 
> Return a copy of the string with leading characters removed. If chars
> is omitted or None, whitespace characters are removed. If given and
> not None, chars must be a string; the characters in the string will be
> stripped from the beginning of the string this method is called on.

I think that last phrase might be responsible for the OP's confusion.
Even now my brain interprets it as meaning the *string* formed by those
characters will be removed from the beginning of the string, not that
each occurrence of any character in that arg string will be removed
from the target.

-Peter




More information about the Python-list mailing list