Newbie: Inheritance of accessors

Will Fitzgerald fitzgerald at
Wed Oct 16 04:44:20 CEST 2002

Mark McEahern wrote:

>[Will Fitzgerald]
>>I'm curious about accessors being inherited from parent classes. Given 
>>the code that follows, and I create an instance:
>> e=S()
>>How do I access the inherited default 'x' in e (inherited from R)?
>In the most natural way imaginable, of course:
>  e.x = 1
>  print e.x
>// m
Thank you very much for your reply.

I guess I should have been clearer. I meant reading the inherited 
*default* value from the parent class. Given the same code (repeated 
below), I see:

 >>> q = R()
 >>> print q.x
 >>> e = S()
 >>> print e.x
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "<stdin>", line 5, in getx
AttributeError: 'S' object has no attribute '_R__x'

Can e *not* inherit to the default value? Or is there a way to call the 
__init__ method for R's superclass (so that 'x' in initialized?).


More information about the Python-list mailing list