Accessing outer class methods from an inner class
I want a python class that has a nested class where the inner class can access the members of the outer class. I understand that normal nesting doesn't even require that the outer class has an instance. I have some code that seems to generate the results I desire and I want feedback on style and unforeseen complications

Code:

    class A():

        def __init__(self,x):
            self.x = x
            self.B = self.classBdef()

        def classBdef(self):
            parent = self

            class B():
                def out(self):
                    print parent.x

            return B

Output:

    >>> a = A(5)
    >>> b = a.B()
    >>> b.out()
    5
    >>> a.x = 7
    >>> b.out()
    7

So, A has an inner class B, which can only be created from an instance of A. Then B has access to all the members of A through the parent variable.

Accessing outer class methods from an inner class
===

I want a python class that has a nested class where the inner class can access the members of the outer class. I understand that normal nesting doesn't even require that the outer class has an instance. I have some code that seems to generate the results I desire and I want feedback on style and unforeseen complications

Code:

    class A():

        def __init__(self,x):
            self.x = x
            self.B = self.classBdef()

        def classBdef(self):
            parent = self

            class B():
                def out(self):
                    print parent.x

            return B

Output:

    >>> a = A(5)
    >>> b = a.B()
    >>> b.out()
    5
    >>> a.x = 7
    >>> b.out()
    7

So, A has an inner class B, which can only be created from an instance of A. Then B has access to all the members of A through the parent variable.
