擅长:python、mysql、java
<p>你的解决方案不正确。使用成员类型在Atom类中创建成员,然后可以通过普通的<code>__getattr__</code>机制访问和设置这些成员。在</p>
<p>示例代码的正确示例:</p>
<pre><code>from __future__ import print_function
import datetime
import os
from atom.api import Atom, Unicode, Range, Typed, observe, Value, Bool
def default_time_factory():
return datetime.datetime.strptime('05.03.2015-5','%d.%m.%Y-%H')
class SimulationCase(Atom):
startDateTime = Typed( datetime.datetime, factory=default_time_factory )
currentDateTime = Typed( datetime.datetime, factory=default_time_factory )
endDateTime = Typed( datetime.datetime, default=default_time_factory()+datetime.timedelta(days=int5) )
incrementTime = Typed( datetime.time, default=datetime.time(1,0,0) )
def main():
case = SimulationCase()
print(case.currentDateTime)
a = datetime.time(1,0,0)
print(a)
#This now works
case.incrementTime = a
if __name__ == '__main__':
main()
</code></pre>