strptime on Unix systems

Malcolm Tredinnick malcolmt at smart.net.au
Wed Dec 22 18:46:34 EST 1999


On Wed, Dec 22, 1999 at 04:46:27PM -0500, Justin Sheehy wrote:
> "Malcolm Tredinnick" <malcolmt at smart.net.au> writes:
> 
> > The following does *not* work under Linux (at least):
> > 
> > import time
> > format = '%a %b %d %H:%M:%S %Z %Y'
> > t = time.localtime(time.time())
>   ^
> (I assume that you meant `tt', and not `t'...
> 
> > timestring = time.strftime(format, tt)		# Works OK
> > timetuple = time.strptime(tt, format)		# Throws ValueError
> > 
> Really?
> 
> I would expect it to break regardless of the value of `format'.  You
> are passing a tuple as the first argument to time.strptime, which is
> expecting a string.
> 
> However, there does seem to be a linux problem here.
> 
> Under FreeBSD and Solaris, at least, the time module works fine with
> the above format string:

Aargh! I should apologise to everybody here and stop posting messages after
Christmas Parties :( My typing was terrible and I should have just
cut-and-paste.  The last line was meant to be
   timetuple = time.strptime(timestring, format)
which breaks on Linux because of a library problem. But I thought it was such
a short segment, I could just retype it. Grrr.

I was even a bit slow catching the error because one of the earlier posters
confirmed the ValueError, but that was probably due to passing tt, rather than
timestring to time.strptime.

My conclusions from this (and private emails a few have sent me):
(1) The problem is with the Linux library
(2) Everybody should, in future, just ignore me (play it safe ... set up a
kill filter).

Sorry.
Malcolm Tredinnick  <-- Going to hide in the freezer for a while.





More information about the Python-list mailing list