我们已经知道,datetime.timedelta(hours = 5)是一个正确的语法。 如何传递一个可以替换下面函数中给出的'hours'的参数?
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()
答案 0 :(得分:5)
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()