How to call the super implementation of a property?
Gonçalo Rodrigues
op73418 at mail.telepac.pt
Tue Jan 21 11:22:03 EST 2003
Hi,
I've posted this question but got no answer so I'm trying it again:
Suppose I override a property in a subclass, e.g.
>>> class test(object):
... def __init__(self, n):
... self.__n = n
... def __get_n(self):
... return self.__n
... def __set_n(self, n):
... self.__n = n
... n = property(__get_n, __set_n)
...
>>> a = test(8)
>>> a.n
8
>>> class test2(test):
... def __init__(self, n):
... super(test2, self).__init__(n)
... def __get_n(self):
... return "Got ya!"
... n = property(__get_n)
...
>>> b = test2(8)
>>> b.n
'Got ya!'
How do I call the super implementation of the n property using super?
The obvious (to me) does not work:
>>> print super(test2, b).n
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
AttributeError: 'super' object has no attribute 'n'
I know I can do
>>> test.n.__get__(b)
8
>>>
But how do I achieve the same using super (for an MI scenario)?
TIA and with my best regards,
G. Rodrigues
More information about the Python-list
mailing list