why the super class can access the subclass's attribute

Jean-Michel Pichavant jeanmichel at sequans.com
Thu Jan 21 11:20:09 CET 2010


yousay wrote:
> I have sees aprogram like this ,i confusing why super class can access
> the subclass's attribute
> ,this is the program,thanks in advance:
> class MyThread(threading.Thread):
>     def join(self):
>         super(MyThread,self).join()
>         return self.result
>
> class Worker(MyThread):
>     import random
>     import pdb
>     pdb.set_trace()
>     def run(self):
>         total = 0
>         for i in range(random.randrange(10,100)):
>             total +=i
>         self.result = total
>
>
>   
I don't thing I got your problem.
But in case  you are talking about 'result', you could probably say that 
"the subclass Worker can access to the super class MyThread 'result' 
attribute".

Also keep in mind that there is no private attributes in python, and 
that any object can access any other object attribute, no matter its 
class. Of course, you dont want to do that.

JM



More information about the Python-list mailing list