[issue1074462] Irregular behavior of datetime.__str__()

Zooko O'Whielacronx report at bugs.python.org
Mon Oct 15 06:15:40 CEST 2007


Zooko O'Whielacronx added the comment:

Here is a note for the next person who comes to this ticket wondering
why isoformat() exhibits this slightly un-Pythonic behavior.  If you
want to use isoformat() to produce, for example, timestamps for your
logfiles, you'll need to do something like the following.  (I do hope
you noticed the documentation and didn't use isoformat() in the naive
way, or your log files will very rarely have a different format than you
expected.)

    d = datetime.datetime.utcfromtimestamp(when)
    if d.microsecond:
        return d.isoformat(" ")[:-3]+"Z"
    else:
        return d.isoformat(" ") + ".000Z"

http://allmydata.org/trac/tahoe/browser/src/allmydata/node.py#L21

----------
nosy: +zooko

_____________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1074462>
_____________________________________


More information about the Python-bugs-list mailing list