I tried writing a custom getter for a class attribute. But I am unable of finding the right syntax in Python. I tried what is mentioned in this question but using the @property
decorator does not seem to work or I am calling it incorrectly.
Class:
class Comment:
def __init__(self):
self.productRecommender = None
@property
def productRecommender(self):
return self.productRecommender if self.productRecommender is not None else 'Onbekend'
Setting the attribute in the code (uses Selenium, comment is an instance of Comment()), should stay None
if class is not found:
try:
comment.recommender = comment.find_element_by_class_name('recommend').text
except NoSuchElementException:
pass
Trying to access the value
comment.productRecommender