Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!txtfeed1.tudelft.nl!tudelft.nl!txtfeed2.tudelft.nl!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'see:': 0.07; 'subject:object': 0.07; 'python': 0.08; '2006,': 0.09; 'nameerror:': 0.09; 'skip:" 60': 0.09; 'win32': 0.12; 'def': 0.13; 'cc:addr:python-list': 0.15; 'mon,': 0.15; '"copyright",': 0.16; '"credits"': 0.16; '"license"': 0.16; '**kwargs)': 0.16; '__init__': 0.16; 'assigns': 0.16; 'instantiated': 0.16; 'returned,': 0.16; 'tab,': 0.16; '\xa0as': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'instance': 0.18; 'yet.': 0.18; 'jan': 0.19; 'cheers,': 0.20; 'suggest': 0.20; '(most': 0.21; 'cc:no real name:2**0': 0.21; 'header:In-Reply-To:1': 0.22; 'sep': 0.23; 'defined': 0.24; 'traceback': 0.24; 'cc:2**0': 0.25; 'process,': 0.25; 'suggestion': 0.25; 'pm,': 0.26; 'import': 0.27; "i'm": 0.27; 'bit': 0.28; 'message-id:@mail.gmail.com': 0.28; 'print': 0.29; 'cc:addr:python.org': 0.29; 'class': 0.29; 'kelly': 0.30; 'framework': 0.30; 'app': 0.31; 'actually': 0.32; 'assigned': 0.32; 'totally': 0.32; "can't": 0.32; "isn't": 0.32; 'it.': 0.33; 'object': 0.33; 'creates': 0.34; 'last):': 0.34; 'yet,': 0.34; 'received:74.125.82': 0.34; 'file': 0.35; 'instead.': 0.36; 'reference': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'using': 0.37; 'happens': 0.37; 'skip:_ 10': 0.37; 'created': 0.38; 'subject:: ': 0.39; 'type': 0.60; 'more': 0.61; 'your': 0.61 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type:content-transfer-encoding; bh=dSYhOdjSSJyl3MqIYf5loasqsbrV6hMut2hMz8ozhV4=; b=x4r6rvO8pPr3IBoAQbJxAWAeSIMcdh1anMmZqIig/3rDx+D+KjK6OID+xfLFxacrjG XjVRa7FfMd4og7qmrR8lWhweXH6c5Zl8KMhiVzf0DmNwx+OYu2WCyPbgJlG2iGf31gc/ hsf5enyZnv0R/ijKxcY9+ZypLS/Zt9gc5oZqM= MIME-Version: 1.0 In-Reply-To: References: From: Ian Kelly Date: Mon, 23 Jan 2012 15:20:55 -0700 Subject: Re: Using an object inside a class To: Jonno Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 51 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327357292 news.xs4all.nl 6857 [2001:888:2000:d::a6]:35541 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19294 On Mon, Jan 23, 2012 at 2:52 PM, Jonno wrote: > On Mon, Jan 23, 2012 at 3:42 PM, Ian Kelly wrote: >> >> Exactly. =A0The line "app =3D MyApp(0)" creates a MyApp instance and the= n >> assigns it to "app". =A0As part of the MyApp creation process, it >> creates a MyFrame, which creates a Tab, which creates a Class1, which >> attempts to reference "app". =A0All 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. >> > That totally makes sense. However I'm not sure I understand your suggesti= on > how to use wx.GetApp() > Isn't the wxApp still not created before Class1 is instantiated so I stil= l > can't call wx.GetApp() in __init__ of Class1 can I? The App object is created and the wx framework already knows about it. It's just not assigned to the app global yet, and the OnInit call has not completed yet. See: Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import wx >>> class MyApp(wx.App): ... def OnInit(self): ... print "wx.GetApp() =3D", wx.GetApp() ... print "app =3D", app ... return True ... >>> app =3D MyApp(0) wx.GetApp() =3D <__main__.MyApp; proxy of > app =3D Traceback (most recent call last): File "", line 1, in File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7823, in __init__ self._BootstrapApp() File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7420, in _BootstrapApp return _core_.PyApp__BootstrapApp(*args, **kwargs) File "", line 4, in OnInit NameError: global name 'app' is not defined Cheers, Ian