how to pass argument to datetime.timedelta
datetime, python, python-3.x
Solution
def check_time(until_when, def_time, how_long):
arg_dict = {def_time:how_long}
dt = datetime.timedelta(**arg_dict)
if until_when- datetime.datetime.now() > dt:
input('Task has been finished.\nPress any key to quit\n')
exit()
See Understanding kwargs in Python and the tutorial.
Problem
We already know that, datetime.timedelta(hours= 5) is a proper syntax. How is it possible to pass an argument that can replace 'hours' as given in the function down below? ``` def check_time(until_when, def_time, how_long): if until_when- datetime.datetime.now() > datetime.timedelta(def_time = how_long): input('Task has been finished.\nPress any key to quit\n') exit() ```