On Thursday, January 9, 2014 9:57:57 AM UTC-5, Chris Angelico wrote:
> And months are more
> complicated still, so it's probably easiest to use strftime:
>
> >>> time.strftime("%Y%m",time.gmtime(ts))
>
> '201401'
strftime is a non-starter at far as "easy" goes. I don't know about you, but I
certainly haven't memorized the table of all the format specifiers. Is month
"m" or "M"? What's "%U" or "%B". Every time I use strftime, I have to go pull
up the docs and read the table. Not to mention that "%z" is not available on
all platforms, and "%s" (which is incredibly useful) is not even documented (I
suspect it's also not available on all platforms).
> So what I'm seeing here is that the direct use of a time_t will cover
> everything in an ugly way, but that a class wrapping it up could fix
> that. And fundamentally, the only problem with datetime (which, for
> the most part, is exactly that wrapper) is that it's unobvious how to
> get a simple UTC timestamp.
>
> Has the unobviousness been solved by a simple recipe? And if so,
> should that tip be added to the datetime module docs somewhere?
No, it would be solved by a built-in method. Recipes are a cop-out. If
something is complicated enough to require a recipe, and used frequently enough
to be worth writing that recipe up and documenting it, you might as well have
gone the one additional step and made it a method.
--
https://mail.python.org/mailman/listinfo/python-list