I am using Python 2.4.2, the latest version currently
available for the system I am using, which is Ubuntu
5.10 for x86.
I was calling the time.strptime() function, and I had
accidentally typed an extra % symbol in the time format
string. If you do this you get a baffling message in
the traceback. The deepest frame of the traceback
looks like this:
File "/usr/lib/python2.4/_strptime.py", line 256, in
pattern
processed_format = "%s%s%s" % (processed_format,
KeyError: '-'
This means that I accidentally put "%-" in my format
string.
What happens if I accidentally put "% " in my format
string? This:
File "/usr/lib/python2.4/_strptime.py", line 256, in
pattern
processed_format = "%s%s%s" % (processed_format,
KeyError: '\\'
It turns out that spaces in the format string are
replaced by r'\s*' by the time the exception happens.
It really freaked me out to see Python complaining
about a backslash, when I hadn't put a backslash into
my format string.
I propose that this library call should be re-written
to catch the exception, and then throw a more sensible
exception, including a statement like: "unknown % code
in format string". In a perfect world this would be
done in such a way that the last frame appearing in the
traceback would be for the call to time.strptime(), and
not show any lines from the guts of time.strptime()
about regular expression compiling.
|