[ python-Bugs-1340337 ] time.strptime() with bad % code throws bad exception
SourceForge.net
noreply at sourceforge.net
Sat Oct 29 06:10:45 CEST 2005
Bugs item #1340337, was opened at 2005-10-27 23:48
Message generated for change (Settings changed) made by nnorwitz
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1340337&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Steve R. Hastings (steveha)
>Assigned to: Brett Cannon (bcannon)
Summary: time.strptime() with bad % code throws bad exception
Initial Comment:
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.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1340337&group_id=5470
More information about the Python-bugs-list
mailing list