string methods of a str subclass

7stud bbxx789_05ss at
Mon Apr 16 12:05:07 CEST 2007

On Apr 16, 3:28 am, "Daniel Nogradi" <nogr... at> wrote:
> I would expect all methods operating on a string instance
> and returning another string instance

Ok, then this:

class A(object):
    def __init__(self, s):
        self.s = s
    def strip(self):
        return self.s

class mystr(A):

x = mystr("x")
print isinstance(x, mystr)
print isinstance(x.strip(), mystr)

"x" is a string, and that is what gets passed to the base class's
__init__ method, and that is what strip() operates on.

More information about the Python-list mailing list