0

I have to convert big legacy Python 2.7 codebase to Python 3.6 and I found that in Python3

datetime.datetime(2020, 05, 09)

does not support leading 0, it throws "invalid token" error.

But it works in Python 2.

What is the best way to make it work in Python 3.6?

Should I write/apply the global search/replace regexp across all codebase to remove the leading 0 in month and day? How this regexp will look like?

May be there is another way to migrate this code?

user3440012
  • 171
  • 2
  • 12
  • For the record, `datetime(2020, 05, 09)` does not actually work in Python 2.7 either! Only up to 07 literals is working (octal). The (easy) solution for cross-compatible Python 2.7/3.x code is just to remove those leading zeros from the source code. – wim Jul 30 '21 at 02:57
  • `import time` and `time.strptime('2020, 05, 09', '%Y, %m, %d')` – Ali Aref Jul 30 '21 at 03:00

0 Answers0