我希望能够使用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 标签尝试了尽可能多的排列。
这些都失败了:
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