[Python-ideas] adding a trim convenience function

George Sakkis george.sakkis at gmail.com
Thu Mar 6 21:29:42 CET 2008


On Thu, Mar 6, 2008 at 3:16 PM, Erick Tryzelaar
<idadesub at users.sourceforge.net> wrote:

> On Thu, Mar 6, 2008 at 11:37 AM, Terry Reedy <tjreedy at udel.edu> wrote:
>
>  fyi, I looked through a bunch of code, and it does seem that there is
>  less need for this than I thought.
>
>  >  Who many such uses are like your 'foo bar for'?
>
>  The case I ran into is that I used in a fashion like
>  'abaaab'.lstrip('ab') before I understood exactly what strip did. The
>  replace trick won't work for me because all of the instances where I
>  used this were in an api, so I couldn't assume that the string i was
>  trimming didn't have other instances of the prefix/suffix in the
>  middle.

What about adding an optional boolean parameter to str.*strip that
treats the argument as either a set of characters (default, just like
now) or an exact string ? Something like

>>> 'abaaab'.lstrip('ab')
''
>>> 'abaaab'.lstrip('ab', exact=True)
'aaab'


George



More information about the Python-ideas mailing list