How to force PyYAML to dump date with a z at the end?
Matthew Wilson <[email protected]>
| Newsgroups | gmane.text.yaml.general |
|---|---|
| Message-ID | <[email protected]> |
I'm trying to write some yaml files with python that can be parsed with ruby. The problem I'm having is that that PyYAML dumps datetime objects in a format that ruby's parser doesn't recognize as a date. Here's the python: >>> import yaml >>> from datetime import datetime >>> dt = datetime.now() >>> yaml.dump(dt) '2009-03-04 22:53:45.031818\n' And then in ruby: irb(main):014:0> YAML::load '2008-09-02 19:18:03.286902' => "2008-09-02 19:18:03.286902" Notice that ruby creates a string. Ruby also creates a string with this format: irb(main):021:0> YAML::load '2009-03-04 00:00:00+00:00' => "2009-03-04 00:00:00+00:00" The only time ruby doesn't make a string is when a Z is at the end, like this: irb(main):022:0> YAML::load '2009-03-04 00:00:00 Z' => Wed Mar 04 00:00:00 UTC 2009 So, how do I force python to put that Z at the end when it dumps datetime objects out? -- Matthew Wilson [email protected] http://tplus1.com ------------------------------------------------------------------------------ Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise -Strategies to boost innovation and cut costs with open source participation -Receive a $600 discount off the registration fee with the source code: SFAD http://p.sf.net/sfu/XcvMzF8H