我通过查看 Nucleic Development Team Atom 的 Property.py 文档找到了一个解决方案。setter 可以通过添加一个带有_set_variable(self,variable)和_get_variable(self) 的函数来完成:
因此,一个可能的解决方案是:
from __future__ import print_function
import datetime
import os
from atom.api import Atom, Unicode, Range, Typed, observe, Value, Bool, Property
class SimulationCase(Atom):
startDateTime = Property()
_startDateTime = Typed(datetime.datetime)
currentDateTime = Property()
_currentDateTime = Typed(datetime.datetime)
endDateTime = Property()
_endDateTime = Typed(datetime.datetime)
incrementTime = Property()
_incrementTime = Typed(datetime.time)
# Getter and setter for startDateTime
def _set_startDateTime(self,startDateTime):
self._startDateTime = startDateTime
def _get_startDateTime(self):
return self._startDateTime
# Getter and setter for currentDateTime
def _set_currentDateTime(self,currentDateTime):
self._currentDateTime = currentDateTime
def _get_currentDateTime(self):
return self._currentDateTime
# Getter and setter for endDateTime
def _set_endDateTime(self,endDateTime):
self._endDateTime = endDateTime
def _get_endDateTime(self):
return self._endDateTime
# Getter and setter for incrementTime
def _set_incrementTime(self,incrementTime):
self._incrementTime = incrementTime
def _get_incrementTime(self):
return self._incrementTime
# Populating the data
def __init__(self):
self._startDateTime = datetime.datetime.strptime('05.03.2015-5','%d.%m.%Y-%H')
self._currentDateTime = self._startDateTime
self._endDateTime = self._startDateTime + datetime.timedelta(days=int(5))
self._incrementTime = datetime.time(1,0,0)
def main():
case = SimulationCase()
print(case.currentDateTime)
print(case.incrementTime)
print(case.endDateTime)
a = datetime.time(2,0,0)
case.incrementTime = a
print(case.incrementTime)
if __name__ == '__main__':
main()