__sub__ for string

Fredrik Lundh fredrik at pythonware.com
Fri Apr 13 05:22:05 EDT 2001


Rikard Bosnjakovic wrote:
> I mean, it wasn't much code:
>
> import UserString
>
> class mystr(UserString.UserString):
>     def __init__(self, data=""):
>         self.data = data
>     def __sub__(self, other):
>         return self.data.replace(other, "")

you mean "if self.data.endswith(other): return self.data[-len(other):]",
don't you?

Cheers /F





More information about the Python-list mailing list