On inner classes

Emile van Sebille emile at fenx.com
Mon Feb 25 22:52:13 CET 2002


"Gonçalo Rodrigues"
> How in the __init__ of the inner class do i acess the instance
> attributes declared in the __init__ of the outer class? In this case the
> instance attribute example?
>

Pass it in when init'ing the outer_class instance?

class outer_class:
    def __init__(self):
        self.example = "just a test"

    class inner_class:
        def __init__(self, outer_self):
            print outer_self.example
    def doit(self):
        ic = self.inner_class(self)

oc = outer_class()
oc.doit()


HTH,

--

Emile van Sebille
emile at fenx.com






More information about the Python-list mailing list