Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19290 > unrolled thread

Re: Using an object inside a class

Started byIan Kelly <ian.g.kelly@gmail.com>
First post2012-01-23 14:42 -0700
Last post2012-01-23 14:42 -0700
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Using an object inside a class Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 14:42 -0700

#19290 — Re: Using an object inside a class

FromIan Kelly <ian.g.kelly@gmail.com>
Date2012-01-23 14:42 -0700
SubjectRe: Using an object inside a class
Message-ID<mailman.4989.1327354997.27778.python-list@python.org>
On Mon, Jan 23, 2012 at 2:22 PM, Jonno <jonnojohnson@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.

Cheers,
Ian

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web