I’m using Python 3.10. I want to convert strings such as “10 MINUTES”, “3 DAYS”, “5 WEEKS”, “42 SECONDS”, etc. into something that datetime.timedelta
can parse.
For example:
"3 DAYS" gets properly parsed and then invokes timedelta(days = 3)
I’m aware of strptime
, but it doesn’t understand strings such as “10 MINUTES”, etc.
I can crank out my own parsing routine to handle this, but I’d prefer not to “re-invent the wheel” if there already is a Python package which can manage this task.
Thank you in advance for any thoughts and suggestions.