mirror of
https://github.com/python/cpython.git
synced 2025-11-25 12:44:13 +00:00
SF 748201: time.strptime() should display format and date on error
Usability fix. Makes the error message more helpful.
This commit is contained in:
parent
627273733f
commit
4a6302b6fe
1 changed files with 2 additions and 1 deletions
|
|
@ -430,7 +430,8 @@ def strptime(data_string, format="%a %b %d %H:%M:%S %Y"):
|
||||||
_regex_cache[format] = format_regex
|
_regex_cache[format] = format_regex
|
||||||
found = format_regex.match(data_string)
|
found = format_regex.match(data_string)
|
||||||
if not found:
|
if not found:
|
||||||
raise ValueError("time data did not match format")
|
raise ValueError("time data did not match format: data=%s fmt=%s" %
|
||||||
|
(data_string, format))
|
||||||
if len(data_string) != found.end():
|
if len(data_string) != found.end():
|
||||||
raise ValueError("unconverted data remains: %s" %
|
raise ValueError("unconverted data remains: %s" %
|
||||||
data_string[found.end():])
|
data_string[found.end():])
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue