A question about Python Classes

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Apr 21 12:30:14 EDT 2011


chad wrote:
> 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
>you did, test is an instance of BaseHandler.
 > isinstance(test, HomeHandler)
< True
 > isinstance(test, BaseHandler)
< True
JM


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /