Using an object inside a class

Jonno jonnojohnson at gmail.com
Mon Jan 23 15:05:53 EST 2012


On Mon, Jan 23, 2012 at 1:44 PM, Jonno <jonnojohnson at gmail.com> 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).
>
> Any ideas why I can reference foo inside the method but not in __init__?
>

If it matters, foo is an instance of wx.App and bar is a wx.Frame within
the app.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20120123/d1a121c8/attachment-0001.html>


More information about the Python-list mailing list