Inheritance and recursion problem
wierd_joe at spamhoo.com
Sat Nov 25 09:32:13 CET 2006
i'm trying to make some user interface objects in python.
I have classes XWindow and XMainWindow(XWindow) (XMainWindow inherited
XWindow have all drawing functionality and Windows object which holds
all child windows.
Function Draw looks like this:
for wnd in self.Windows:
Now in main module i make objects:
Now the problem:
When i call RootWindow.Draw() he calls wnd.Draw where wnd is XMainWindow
from RootWindow's Windows collection.
Now, we are in MW's Draw and MW's Windows collection should be empty
but somehow he has itself (well, new instance of XMainWindow) in this
collection and i got unlimited reference.
While writing this post i tried something:
instead of using RootWindow.Windows.append(MW)
i used RootWindow.Windows=[MW] and now it's OK.
I'm happy now, my code works, but i don't know what was happening there:
why append made new instance of object instead of passing existing object.
More information about the Python-list