strptime on Unix systems

Malcolm Tredinnick malcolmt at smart.net.au
Tue Dec 21 19:01:07 EST 1999


On a Linux technical support mailing list I am on, somebody recently posted a
question about Python and although I was able to answer it, the logic behind
the answer has me stumped:

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())
timestring = time.strftime(format, tt)		# Works OK
timetuple = time.strptime(tt, format)		# Throws ValueError

The reason for this problem is that strftime and strptime are based on their
C-library counterparts and according the man pages, while strftime does take a
%Z modifier in the format string, strptime does NOT understand this modifier.
(so you can remove the %Z from format and the above snippet is fine.)

Two questions:
(1) What is the story on other Unix systems? Is this a general problem (I hope
not)?

(2) Is there any logic hidden behind the fact that one direction takes %Z and
the other does not?

Cheers,
Malcolm Tredinnick

--
Telepath required. You know where to apply...




More information about the Python-list mailing list