class Books():
def __init__(self):
self.__dict__['referTable'] = 1
@property
def referTable(self):
return 2
book = Books()
print(book.referTable)
print(book.__dict__['referTable'])
Running:
vic@ubuntu:~/Desktop$ python3 test.py
2
1
Books.referTable being a data descriptor is not shadowed by book.__dict__['referTable']:
The
property()function is implemented as a data descriptor.
Accordingly, instances cannot override the behavior of a property.
To shadow it, instead of property built-in descriptor i must use my own descriptor. Is there a built in descriptor like property but which is non-data?
To expand on my comment, why not simply something like this:
Now, I’d like to note that I don’t think this is good design, and you’d be much better off using a private variable rather than accessing
__dict__directly. E.g:In short, the answer is no, there is no alternative to
property()that works in the way you want in the Python standard library.