Problem subclassing (Newbie)

Shahla Almasri sa at almasris.com
Sat Sep 24 17:31:23 CEST 2005


I finally figured what I was missing. I forgot to import my Widget 
class!!! I have imported Tkinter in the module for other GUI related 
stuff. So Python was testing my Button class against Tkinter's Widget 
class, and that's why the result was False. It finally made sense :)

Thank you Anand and Laszlo for your reply. 

Cheers,

-Shahla

> 
> >Then I have an instance of class Button called obj. My probelm is 
that 
> >the test isinstance(obj, Widget) resturns False! 
> >
> You must have a typo somewhere. Please try this little test program.
> 
>  >>> class Widget(object):
> ...       pass
> ...
>  >>> class Button(Widget):
> ...       pass
> ...
>  >>> b = Button()
>  >>> isinstance(b,Widget)
> True
>  >>> isinstance(b,Button)
> True
>  >>> issubclass(Widget,Button)
> False
>  >>> issubclass(Button,Widget)
> True
>  >>>
> 
> 
> 
> 

-- 




More information about the Python-list mailing list