the Gravity of Python 2

Chris Angelico rosuav at gmail.com
Thu Jan 9 15:35:05 EST 2014


On Fri, Jan 10, 2014 at 3:21 AM, Roy Smith <roy at panix.com> wrote:
> 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).
>

Have you ever used a regular expression? Does it bother you that both
percent-formatting and str.format() have compact/cryptic
mini-languages? Why is it a problem to have a mini-language for
formatting dates? It at least follows a measure of common sense,
unlike the PHP date function. In fact, I've given end users the
ability to enter strftime strings (eg to construct a filename), and
it's worked just fine. *Non-programmers* can figure them out without
much difficulty.

ChrisA



More information about the Python-list mailing list