Lost in the inheritance tree... THANKS!
Adam Munoz Lopez
adam1800uk at yahoo.co.uk
Mon Jun 6 12:06:53 EDT 2005
Thanks a lot for your quick response. I actually just
found the answer by myself before reading your reply.
Just printed out the code and read it. The mistake was
pretty obvious then. Yes, Ill try your suggestion. I
was just trying to experiment a bit with inheritance
to understand how it works better.
Once again thanx a lot. Its the first time I post and
Im pretty impressed by the speed with which you guys
replied.
Adam.
--- Jordan Rastrick <jrastrick at student.usyd.edu.au>
wrote:
> Although you get infinite recursion with this code,
> you still get
> enough information on the error from the interpreter
> to help you debug.
>
> Running IDLE, I get a traceback of:
>
> File "C:/Documents and
> Settings/Jordan/Desktop/more_blah.py", line 11,
> in __init__
> self.createFrames()
> File "C:/Documents and
> Settings/Jordan/Desktop/more_blah.py", line
> 19, in createFrames
> textFrame=TextFrame(self,300,600)
> File "C:/Documents and
> Settings/Jordan/Desktop/more_blah.py", line
> 31, in __init__
> RootFrame.__init__(self,parent,myHeight,myWidth)
>
> repeated indefinitely. At a glance, this tells you:
>
> * That __init__ (of the RootFrame method) calls
> self.createFrames()
> * createFrames(), in turn, calls
> TextFrame(self,300,600)
> * This leads to RootFrame.__init__ being called once
> more
>
> So theres youre infinite recursion. RootFrame's
> __init__ calls
> createFrames which creates a new TextFrame - meaning
> TextFrame.__init__
> gets called, and this calls its parent's __init__
> method, and so on ad
> infinitum.
>
> This is a pretty good demonstration of the prinicple
> that you should do
> as little as is nessecary to create an object - if
> possible, try to
> calling other methods on an object in its __init__
> method.
>
> Without knowing more about youre program, and with
> only limited GUI
> building experience (and none in Python), I'd guess
> the most likely
> solution is for TextFrame to inherit from
> Tkinter.Frame directly -
> having it inheret from RootFrame doesn't really make
> much sense as far
> as I can see. TextFrame is, I would guess, intended
> as a component of
> RootFrame, not a subclass. Thats another important
> OO prinicple - don't
> overuse inheritance, often simple composition (one
> object having
> another as an attribute) is the right solution.
>
> If TextFrame really is supposed to inherit from
> RootFrame, try to
> explain why.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
___________________________________________________________
Yahoo! Messenger - NEW crystal clear PC to PC calling worldwide with voicemail http://uk.messenger.yahoo.com
More information about the Python-list
mailing list