looping wrote: > Hi, > my question is on this example: > > class MyStr(str): > def hello(self): > print 'Hello !' > > s1 = MyStr('My string') > s2 = MyStr('My second string') > > s1.hello() > s2.hello() > > s = s1 + s2 > > s.hello() > >>>> > Hello ! > Hello ! > Traceback (most recent call last): > File "<string>", line 204, in run_nodebug > File "<module1>", line 13, in <module> > AttributeError: 'str' object has no attribute 'hello' > > How could I get a type MyStr from the 'plus' (__add__) operation > without overriding it in my class ?
You can't. > I need to override *every* operator I like to use ? Yes. Diez -- http://mail.python.org/mailman/listinfo/python-list