On inner classes

Gonçalo Rodrigues op73418 at mail.telepac.pt
Mon Feb 25 16:23:13 EST 2002


On Mon, 25 Feb 2002 12:31:38 -0700, "Bjorn Pettersen"
<BPettersen at NAREX.com> wrote:

>> From: Gonçalo Rodrigues [mailto:op73418 at mail.telepac.pt] 
>> 
>> Suppose we have something like
>> 
>> class <name>:
>>     class <name>:
>>         <whatever>
>>     <whatever>
>> 
>> that is, a class defined inside another. How can the inner 
>> class acess the methods/attributes of the outer one?
>
>I'm assuming you're meaning something like:
>
>  class Outer:
>     def outerMethod(self):
>        class Inner:
>           def innerMethod(this):
>              self.outerMethod() # call class Outer's outerMethod
>
>-- bjorn

Actually no. Let me be more specific

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

    class inner_class:
        def __init__(self):
            <whatever>

and now, specifically:

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?




More information about the Python-list mailing list