-2

I want to have the function like the following

unit = "days"
datetime.datetime.now() + datetime.timedelta(unit = 1)

Where in the unit could be days, hours, and minutes etc., which may be changed according to the the time shift unit.

Is there any way to do it in a fast way?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Kimmi
  • 591
  • 2
  • 7
  • 22

1 Answers1

2

You can give keyword arguments using a dictionary as follows:

args = {'days':1}
datetime.timedelta(**args)
Rob Watts
  • 6,866
  • 3
  • 39
  • 58