In the code below I would expect that it shouldn't matter if I use the property val
or call the function get_val
. The output should be the same.
#! /usr/bin/env python
class A():
def get_val(self):
print(self)
raise NotImplementedError
val = property(get_val)
class B(A):
def __init__(self):
self.b_val = "foo\n"
def get_val(self):
print(self)
return self.b_val
b = B()
print(b.get_val())
print(b.val)
But the output I get is:
<__main__.B object at 0x0000014BD2BBE898>
foo
<__main__.B object at 0x0000014BD2BBE898>
Traceback (most recent call last):
File "prop_override_test.py", line 20, in <module>
print(b.val)
File "prop_override_test.py", line 6, in get_val
raise NotImplementedError
NotImplementedError
Why doesn't the property use the overriden get_val
function?
I use python version 3.6.2
python --version
Python 3.6.2