access surrounding class

Pearu Peterson pearu at cens.ioc.ee
Thu Dec 5 18:07:27 EST 2002


On 5 Dec 2002, Simon wrote:

> class theholy:
>     def dosth(self):
>         print "a grrrail??"
>         self.coconut=1231
>         self.rabbit=12
>         class snake:
>             def donothing(self):
>                 print "yes, a grrrail"
>                 # NOW... how can I get the value of coconut?
>                 # super.self.coconut=1423: ????
>                 # does not work
>         a=snake()
>         a.donothing()
> a=theholy()
> a.dosth()
> 
> How can I access coconut or rabbit from within snake??

Define

class theholy:
     def dosth(self):
         print "a grrrail??"
         self.coconut=1231  
         self.rabbit=12     
         class snake:
             super = self      
             def donothing(self): 
                 print "yes, a grrrail"
                 # NOW... how can I get the value of coconut?
                 # A: use self.super.coconut
                 self.super.coconut = 1423
         a=snake()
         a.donothing()

Pearu





More information about the Python-list mailing list