I'm implementing a class in Python which has many properties. Here's an example of a property:
class Test:
def __init__(self):
self._value = None
def get_value(self):
if self._value is None:
self._value = datetime.datetime.now()
return self._value
def set_value(self, new_value):
self._value = new_value
value = property(get_value, set_value)
This seems like a lot of code.
Is there a more concise way to implement this pattern? I'm using PyCharm if that makes any difference.
datetime.datetime.nowto provide the initial value for all the properties.)datetime, I was trying to provide a concise example.