Inheritance and recursion problem
Spiro
wierd_joe at spamhoo.com
Sat Nov 25 03:32:13 EST 2006
Hi all,
i'm trying to make some user interface objects in python.
I have classes XWindow and XMainWindow(XWindow) (XMainWindow inherited
from XWindow)
XWindow have all drawing functionality and Windows[] object which holds
all child windows.
Function Draw looks like this:
def Draw(self):
self.Back.blit
for wnd in self.Windows:
wnd.Draw(OffsetX, OffsetY)
Now in main module i make objects:
RootWindow=XWindow()
MW=XMainWindow()
RootWindow.Widnows.append(MW)
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
mailing list