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


Groups > comp.lang.python > #19294

Re: Using an object inside a class

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 <ian.g.kelly@gmail.com>
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 <CAGz2ECYY9bpNrY3aOS95dwi_vC4p0KHQtERLF51pFHFTaKv6Tg@mail.gmail.com>
References <CAGz2ECYwdnB2ZoTo-DXHhO1_MzdjWeYB+nxeNJ+xivPa8N-tVA@mail.gmail.com> <jfkfn3$92a$1@dough.gmane.org> <CAGz2ECYB=__eKdhdbgWDzRY2DSW4ZcFzuobQCMJFPogV0hcOJA@mail.gmail.com> <CALwzidmYEc9q1ve7u1Vgu-AAVJ6ZBrF36hCZ_=fndvuAFgXMfg@mail.gmail.com> <CAGz2ECYY9bpNrY3aOS95dwi_vC4p0KHQtERLF51pFHFTaKv6Tg@mail.gmail.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 23 Jan 2012 15:20:55 -0700
Subject Re: Using an object inside a class
To Jonno <jonnojohnson@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4992.1327357292.27778.python-list@python.org> (permalink)
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

Show key headers only | View raw


On Mon, Jan 23, 2012 at 2:52 PM, Jonno <jonnojohnson@gmail.com> wrote:
> On Mon, Jan 23, 2012 at 3:42 PM, Ian Kelly <ian.g.kelly@gmail.com> wrote:
>>
>> 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.
>>
> That totally makes sense. However I'm not sure I understand your suggestion
> how to use wx.GetApp()
> Isn't the wxApp still not created before Class1 is instantiated so I still
> 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() =", wx.GetApp()
...         print "app =", app
...         return True
...
>>> app = MyApp(0)
wx.GetApp() = <__main__.MyApp; proxy of <Swig Object of type 'wxPyApp
*' at 0x18d8fc0> >
app =
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  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 "<stdin>", line 4, in OnInit
NameError: global name 'app' is not defined

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 15:20 -0700

csiph-web