A question about Python Classes

Rafael Durán Castañeda rafadurancastaneda at gmail.com
Thu Apr 21 12:28:28 EDT 2011


You did:

>>> class BaseHandler:
...     def foo(self):
...             print "Hello"
...
>>> class HomerHandler(BaseHandler):
...     pass
...
>>> test = HomerHandler()
>>> test.foo()
Hello
>>> isinstance(test, BaseHandler)
True
>>> isinstance(test, HomerHandler)
True
>>>

You could say test is a "BaseHandler of type HomerHandler"



2011/4/21 chad <cdalten at gmail.com>

> Let's say I have the following....
>
> class BaseHandler:
>    def foo(self):
>        print "Hello"
>
> class HomeHandler(BaseHandler):
>    pass
>
>
> Then I do the following...
>
> test = HomeHandler()
> test.foo()
>
> How can HomeHandler call foo() when I never created an instance of
> BaseHandler?
>
> Chad
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110421/793ec8b8/attachment-0001.html>


More information about the Python-list mailing list