[Python-Dev] User's complaints (original) (raw)

"Martin v. Löwis" martin at v.loewis.de
Wed Jul 12 08:34:49 CEST 2006


skip at pobox.com wrote:

The way I used to format dates using time.strftime does indeed no longer work.

Python 2.3: >>> import time >>> time.strftime("%Y-%m-%d", (2005, 6, 4) + (0,)*6) '2005-06-04'

Is there any specific reason you couldn't write

"%d-%02d-%02d" % (2005, 6, 4)

(i.e. not use strftime at all)? It seems strange to fake a time tuple just to use that function, in particular if the time formatting should not use any locale-specific output.

I don't actually run into this problem as I've pretty much converted to use datetime in new code. I also realize that's not documented as the way it should be done, but I'm fairly certain it was common usage before the datetime module came along. Still, it is a bit annoying that the (undocumented, but I think de facto) commonly used idiom no longer works.

I guess this was caused by this change:

/* Checks added to make sure strftime() does not crash Python by
   indexing blindly into some array for a textual representation
   by some bad index (fixes bug #897625).

   No check for year since handled in gettmarg().
*/

So this was changed in response to a bug report about a crash.

Regards, Martin



More information about the Python-Dev mailing list