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


Groups > comp.lang.python > #19290

Re: Using an object inside a class

References <CAGz2ECYwdnB2ZoTo-DXHhO1_MzdjWeYB+nxeNJ+xivPa8N-tVA@mail.gmail.com> <jfkfn3$92a$1@dough.gmane.org> <CAGz2ECYB=__eKdhdbgWDzRY2DSW4ZcFzuobQCMJFPogV0hcOJA@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2012-01-23 14:42 -0700
Subject Re: Using an object inside a class
Newsgroups comp.lang.python
Message-ID <mailman.4989.1327354997.27778.python-list@python.org> (permalink)

Show all headers | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web