Using an object inside a class
ian.g.kelly at gmail.com
Mon Jan 23 16:42:43 EST 2012
On Mon, Jan 23, 2012 at 2:22 PM, Jonno <jonnojohnson at gmail.com> wrote:
>> References inside functions are resolved when the function is called. So
>> purely from what you have presented above, it would seem that 'foo' is
>> defined between the call to __init__ and a later call to method1.
> I have a strong suspicion that this is what's happening.
> Method1 is called on a button push when MainLoop is running so obviously foo
> (the main wx.App) exists by then.
> I must have somehow be initializing Class1 before foo = MyApp() happens.
Exactly. The line "app = MyApp(0)" creates a MyApp instance and then
assigns it to "app". As part of the MyApp creation process, it
creates a MyFrame, which creates a Tab, which creates a Class1, which
attempts to reference "app". All of this happens before that
"MyApp(0)" call has returned, so the result of that call has not
actually been assigned to "app" yet.
I suggest using wx.GetApp() instead.
More information about the Python-list