1

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'
wjandrea
  • 28,235
  • 9
  • 60
  • 81
cheezsteak
  • 2,731
  • 4
  • 26
  • 41
  • 4
    The ISO format itself didn't change, but Python did. Read the docs: [_"Changed in version 3.11: Previously, this method only supported formats that could be emitted by `date.isoformat()` or `datetime.isoformat()`."_](https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat) See also https://docs.python.org/3/whatsnew/3.11.html#datetime. – jonrsharpe Aug 07 '23 at 17:34

0 Answers0