[Tutor] lstrip() question

Tim Johnson tim at johnsons-web.com
Mon Feb 2 16:54:22 EST 2004


Things Karl.
Right on the money!
* Karl Pflästerer <sigurd at 12move.de> [040202 12:31]:
> On  2 Feb 2004, Tim Johnson <- tim at johnsons-web.com wrote:
> 
> > It appears that lstrip() will not do this
> > as this console session using version 2.2.2
> > seems to demonstrate:
> >>>> tmp1 = 'real estate broker courtesy'
> >>>> tmp2 = tmp1.lstrip('<br>')
> >>>> tmp2
> > 'eal estate broker courtesy'
> 
> > It looks like '<br>' is being treated as
> > a set rather than a substring.
> > (that's why the 'r' was removed)
> 
> Yes; strip works with characters.
> 
> > Is there a builtin
> > python method to strip leading substrings? Or do
> > I have to do something using startswidth()?
> 
> I would use a regexp.
> 
> >>> tmp1 = '<br>real estate broker courtesy'
> >>> import re
> >>> re.sub('^<br>*', '', tmp1)
> 'real estate broker courtesy'
> >>> tmp1 = 'real estate broker courtesy'
> >>> re.sub('^<br>*', '', tmp1)
> 'real estate broker courtesy'
> 
> 
> 
>    Karl
> -- 
> Please do *not* send copies of replies to me.
> I read the list
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor

-- 
Tim Johnson <tim at johnsons-web.com>
      http://www.alaska-internet-solutions.com



More information about the Tutor mailing list