Re: 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]> |
Thanks Markus! This is really useful. On Thu, Mar 5, 2009 at 3:43 AM, Markus Jarderot <[email protected]> wrote: > Oops... forgot to include the list as recipient. > > Matthew Wilson skrev: > > So, how do I force python to put that Z at the end when it dumps > datetime objects out? > > > You could set another representer for datetime objects: > >>>> import yaml, datetime >>>> yaml.add_representer(datetime.datetime, lambda self, data: >>>> self.represent_scalar('tag:yaml.org,2002:timestamp', data.isoformat(' ') + ' >>>> Z')) >>>> yaml.dump(datetime.datetime.now()) > '2009-03-05 09:16:09.968000 Z\n...\n' >>>> yaml.load(_) > datetime.datetime(2009, 3, 5, 9, 16, 9, 968000) > > > ------------------------------------------------------------------------------ > 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 > _______________________________________________ > Yaml-core mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/yaml-core > > -- 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