Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19289
| Path | csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!rt.uk.eu.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!news.nosignal.org!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <bsk16@case.edu> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.003 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'app,': 0.07; 'subject:object': 0.07; 'terry': 0.07; 'python': 0.08; 'called.': 0.09; 'foo': 0.09; 'initialized': 0.09; 'pointers': 0.09; 'def': 0.13; "hasn't": 0.13; 'mon,': 0.15; '__init__': 0.16; 'did.': 0.16; 'foo.': 0.16; 'frame,': 0.16; 'initializes': 0.16; 'reedy': 0.16; 'stripped': 0.16; '\xa0def': 0.16; 'wrote:': 0.16; '>>>': 0.18; 'exists': 0.18; 'instance': 0.18; 'convert': 0.19; 'jan': 0.19; 'trying': 0.20; 'posting': 0.20; 'later': 0.21; 'tells': 0.21; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'figure': 0.23; 'obviously': 0.23; 'somehow': 0.23; 'though.': 0.23; 'defined': 0.24; 'code': 0.25; 'pm,': 0.26; 'url:mailman': 0.26; 'function': 0.27; "i'm": 0.27; 'bit': 0.28; 'script': 0.28; 'message-id:@mail.gmail.com': 0.28; 'seem': 0.29; 'class': 0.29; 'definition': 0.30; 'exist.': 0.30; 'oop': 0.30; '(the': 0.30; 'url:listinfo': 0.30; 'pretty': 0.30; 'yet': 0.32; 'it.': 0.33; 'to:addr:python-list': 0.33; 'object': 0.33; 'there': 0.33; 'creates': 0.34; 'received:209.85.212': 0.34; 'too': 0.34; 'rather': 0.34; 'purely': 0.34; 'then.': 0.34; 'running': 0.35; 'things': 0.35; 'finished': 0.35; 'suggestions': 0.35; 'url:python': 0.36; 'class.': 0.36; 'push': 0.36; 'reference': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'another': 0.37; 'skip:_ 10': 0.37; 'getting': 0.37; 'references': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'created': 0.38; 'skip:\xa0 10': 0.38; "i'd": 0.39; 'url:org': 0.39; 'why': 0.39; "what's": 0.39; 'being': 0.39; 'strong': 0.39; 'called': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'order': 0.60; 'more': 0.61; 'happen': 0.61; 'presented': 0.62; 'here': 0.64; 'details': 0.65; 'teach': 0.70; 'relevant': 0.70; 'heavy': 0.71; 'details.': 0.71; '"foo"': 0.84; "'foo'": 0.84; 'reorganize': 0.84; 'run?': 0.84 |
| MIME-Version | 1.0 |
| In-Reply-To | <CAGz2ECYB=__eKdhdbgWDzRY2DSW4ZcFzuobQCMJFPogV0hcOJA@mail.gmail.com> |
| References | <CAGz2ECYwdnB2ZoTo-DXHhO1_MzdjWeYB+nxeNJ+xivPa8N-tVA@mail.gmail.com> <jfkfn3$92a$1@dough.gmane.org> <CAGz2ECYB=__eKdhdbgWDzRY2DSW4ZcFzuobQCMJFPogV0hcOJA@mail.gmail.com> |
| Date | Mon, 23 Jan 2012 16:40:13 -0500 |
| Subject | Re: Using an object inside a class |
| From | Benjamin Kaplan <benjamin.kaplan@case.edu> |
| To | python-list@python.org |
| X-Gm-Message-State | ALoCoQknJ5QehDKUBUYnSEY+E403PruMH/No4sL1mpZ0id78d9HzcCbWZ7u+uEb/ctJ8f+bg0o4q |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Content-Transfer-Encoding | quoted-printable |
| X-Junkmail-Whitelist | YES (by domain whitelist at mpv1.tis.cwru.edu) |
| 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.4988.1327354823.27778.python-list@python.org> (permalink) |
| Lines | 78 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1327354823 news.xs4all.nl 6899 [2001:888:2000:d::a6]:40519 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:19289 |
Show key headers only | View raw
On Mon, Jan 23, 2012 at 4:22 PM, Jonno <jonnojohnson@gmail.com> wrote: > > > On Mon, Jan 23, 2012 at 2:25 PM, Terry Reedy <tjreedy@udel.edu> wrote: >> >> On 1/23/2012 2:44 PM, Jonno wrote: >>> >>> I have a pretty complicated bit of code that I'm trying to convert to >>> more clean OOP. >>> >>> Without getting too heavy into the details I have an object which I am >>> trying to make available inside another class. The reference to the >>> object is rather long and convoluted but what I find is that within my >>> class definition this works: >>> >>> class Class1: >>> def __init__(self): >>> >>> def method1(self): >>> foo.bar.object >>> >>> But this tells me "global name foo is not defined": >>> >>> class Class1: >>> def __init__(self): >>> foo.bar.object >>> >>> Obviously I want the object to be available throughout the class (I left >>> out the self.object = etc for simplicity). >> >> >> Perhaps you left out some relevant details. >> > I'm sure I did. Part of the reason I'm not posting the whole code is that > I'm trying to teach myself OOP as part of this process. I want to figure out > what is wrong as much as possible by myself. I really appreciate the > pointers and suggestions though. > >> >> >>> Any ideas why I can reference foo inside the method but not in __init__? >> >> >> 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. > Is there a good reference on the order that things happen in python when a > single script is run? > "foo = MyApp()" creates an instance of MyApp, initializes it, and then binds it to the name foo. If Class1 is being initialized in MyApp.__init__, then the MyApp instance hasn't finished being created yet so the name "foo" doesn't exist. > In the meantime here is my stripped down script (foo = app, bar = frame, > object = graph_panel). I'd welcome all suggestions to reorganize it. > > > > -- > http://mail.python.org/mailman/listinfo/python-list >
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Using an object inside a class Benjamin Kaplan <benjamin.kaplan@case.edu> - 2012-01-23 16:40 -0500
csiph-web