[Python-Dev] str.strip() enhancement

Josiah Carlson jcarlson at uci.edu
Sun Sep 4 00:20:52 CEST 2005

"Raymond Hettinger" <raymond.hettinger at verizon.net> wrote:
> [Jonny Reichwald]
> > I would like to suggest a small enhancement to str.strip().
> > By expanding its current form, where it only takes a char list, to
> > taking any list containing either char lists or string lists, it is
> > possible to remove entire words from the stripped string.
>  . . .
> > Would this be useful for anyone else besides me?
> Probably not.

There is also the point that this functionality is a 4-line function...

def trim_endings(strng, endings):
    for ending in endings:
        if ending and string.endswith(ending):
            return strng[:-len(ending)]

 - Josiah

More information about the Python-Dev mailing list