Why can Python 3.11 parse this ISO datetime but Python 3.9 can't?

34 Views Asked by At

On the same input datetime.fromisoformat succeeds in Python 3.11 but fails in Python 3.9. Did the ISO format change between minor versions of Python? If so, what changed?

Python 3.11.3 (main, Jun  5 2023, 09:32:32) [GCC 13.1.1 20230429] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.fromisoformat('2022-11-21T19:44:27.292977Z')
datetime.datetime(2022, 11, 21, 19, 44, 27, 292977, tzinfo=datetime.timezone.utc)
Python 3.9.17 (main, Jun 26 2023, 03:30:25)
[GCC 13.1.1 20230429] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from datetime import datetime
>>> datetime.fromisoformat('2022-11-21T19:44:27.292977Z')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Invalid isoformat string: '2022-11-21T19:44:27.292977Z'
0

There are 0 best solutions below