【发布时间】:2011-05-11 04:20:06
【问题描述】:
我希望能够使用datetime.datetime.now() PyYAML 创建一个日期时间对象。调用一些函数很容易:
>>> y = """#YAML
... description: Something
... ts: !!python/object/apply:time.time []"""
>>> yaml.load(y)
{'description': 'Something', 'ts': 1289955567.940973}
>>>
但是,我似乎不知道如何获得datetime.now()。我已经尝试使用各种python yaml tags 调用尽可能多的排列。
这些都失败了:
tests = [
'dt: !!python/object:datetime.datetime.now []',
'dt: !!python/object/new:datetime.datetime.now []',
'dt: !!python/object/apply:datetime.datetime.now []',
]
for y in tests:
try:
print yaml.load(y)
except Exception, err:
print '==>', err
【问题讨论】: