__sub__ for string

Rikard Bosnjakovic bos at hack.org
Fri Apr 13 05:05:31 EDT 2001


I hope I can get a better answer here:

Why isn't __sub__ defined for the internal strings? I want a good reason
for that, and not the "Go C++ if you want to do shit like that" that I
got on #python.

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, "")

>>> s = mystr("foo bar foo foo foo bar")
>>> s - "foo"
' bar    bar'


-- 
Rikard Bosnjakovic - http://bos.hack.org/cv/ - ICQ: 1158217

Anyone sending unwanted advertising e-mail to my address will be
charged $250 for network traffic and computing time. By extracting my
address from this message or its header, you agree to these terms.



More information about the Python-list mailing list