bizarre behavior using .lstrip

Jeremy Dillworth j_k_wd at bellsouth.net
Sat Sep 20 04:43:27 CEST 2003


As an alternative you could use re.sub()

>>> import re
>>> s = 'chg cbonn_fee'
>>> print re.sub('chg ', '', s)
cbonn_fee


On Friday 19 September 2003 8:11 pm, Peter Hansen wrote:
> Pete Jereb wrote:
> > Python 2.3 (#46, Jul 29 2003, 18:54:32) [MSC v.1200 32 bit (Intel)] on
> > win32
> >
> > >>> s = 'chg bonn_fee'
> > >>> print s
> >
> > chg bonn_fee
> >
> > >>> print s.lstrip('chg ')
> >
> > bonn_fee
> >
> > >>> s = 'chg conn_fee'
> > >>> print s
> >
> > chg conn_fee
> >
> > >>> print s.lstrip('chg ')
> >
> > onn_fee
> >
> > 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.
>
> -Peter






More information about the Python-list mailing list