string methods of a str subclass

7stud bbxx789_05ss at yahoo.com
Mon Apr 16 06:05:07 EDT 2007


On Apr 16, 3:28 am, "Daniel Nogradi" <nogr... at gmail.com> 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):
    pass

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