This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author skip.montanaro
Recipients belopolsky, elixir, ezio.melotti, gvanrossum, lemburg, r.david.murray, skip.montanaro, terry.reedy, tim.peters, vstinner
Date 2013-11-06.18:22:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <CANc-5Ux4R7aO5KXBBXCRVywfVxbEwO8YwnywgE5MAyzSrXqhZQ@mail.gmail.com>
In-reply-to <1383758454.87.0.712458886436.issue19475@psf.upfronthosting.co.za>
Content
> I am afraid that the rounding issues may kill this proposal.  Can we start with something simple?  For example, we can start with show=None keyword argument and allow a single value 'microseconds' (or 'us').  This will solve the issue at hand with a reasonable syntax: t.isoformat(show='us').  If other resolutions will be required, we can later add more values and may even allow t.isoformat(show=2) to show 2 decimal digits.

I don't think the meaning of this proposed show keyword argument
should be overloaded as you suggest. If you show microseconds, just
show all of them.

Furthermore...

If we go far enough back, my original problem was really that the
inclusion of microseconds in csv module output was inconsistent,
making it impossible for me to later parse those values in another
script using a fixed strptime format. Since the csv module uses str()
to convert input values for output, nothing you do to isoformat() will
have any effect on my original problem.

In my own code (where I first noticed the problem) I acquiesced, and
changed this

d["time"] = now

to this:

d["time"] = now.strftime("%Y-%m-%dT%H:%M:%S.%f")

where "now" is a datetime object. I thus guarantee that I can parse
these timestamps later using the same format. I realize the inclusion
of "T" means my fields changed in other ways, but that was
intentional, and not germane to this discussion.

So, fiddle all you want with isoformat(), but do it right. I vote that
if you want to add a show parameter it should simply include all
fields down to that level, omitting any lower down. If people want to
round or truncate things you can give them that option, returning a
suitably adjusted, new datetime object. I don't think rounding,
truncation, or other numeric operations should be an element of
conversion to string form. This does not happen today:

>>> import datetime
>>> x = datetime.datetime.now()
>>> x
datetime.datetime(2013, 11, 6, 12, 19, 5, 759020)
>>> x.strftime("%Y-%m-%d %H:%M:%S")
'2013-11-06 12:19:05'

(%S doesn't produce "06")

Skip
History
Date User Action Args
2013-11-06 18:22:31skip.montanarosetrecipients: + skip.montanaro, lemburg, gvanrossum, tim.peters, terry.reedy, belopolsky, vstinner, ezio.melotti, r.david.murray, elixir
2013-11-06 18:22:31skip.montanarolinkissue19475 messages
2013-11-06 18:22:31skip.montanarocreate