Python: how to call a property of the base class if this property is being overwritten in the derived class?

You want to call the base class function which is called by property.

You want to call the base class function which is called by property: class FooBar(Foo): @property def bar(self): # return the same value # as in the base class return Foo. Bar(self) This is the most obvious thing to try I think - but it does not work because bar is a property, not a callable. But a property is just an object, with a getter method to find the correponding attribute: class FooBar(Foo): @property def bar(self): # return the same value # as in the base class return Foo.bar.

Fget(self).

1... and Foo.bar. Fset(self, c) for the setter – Jarret Hardie Jun 20 '09 at 12:10 Thank you!.... – Matt Joiner Jul 6 '10 at 7:53.

Try @property def bar: return super(FooBar, self). Bar Although I'm not sure if python supports calling the base class property. A property is actually a callable object which is set up with the function specified and then replaces that name in the class.

This could easily mean that there is no super function available. You could always switch your syntax to use the property() function though: class Foo(object): def _getbar(self): return 5 def _setbar(self, a): print a bar = property(_getbar, _setbar) class FooBar(Foo): def _getbar(self): # return the same value # as in the base class return super(FooBar, self). _getbar() def bar(self, c): super(FooBar, self).

_setbar(c) print "Something else" bar = property(_getbar, _setbar) fb = FooBar() fb. Bar = 7.

Super should do the trick: return super(). Bar In Python 2. X you need to use the more verbose syntax: return super(FooBar, self).bar.

TypeError: super() takes at least 1 argument (0 given) – Aaron Maenpaa Jun 20 '09 at 11:49 3 super( MyClass, self ).bar() – S. Lott Jun 20 '09 at 11:50 2 I guess (well, judging by the link :P), this answer is python3-related. In python3 super() can take zero arguments, yes.

– shylent Jun 20 '09 at 12:01 super() works without arguments in Python 3 and is equivalent to super(MyClass, self) but more readable in my book. – Pankrat Jun 20 '09 at 12:02.

Class Base(object): def method(self): print "Base method was called" class Derived(Base): def method(self): super(Derived,self).method() print "Derived method was called" d = Derived() d.method() (that is unless I am missing something from your explanation).

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions