我正在尝试在 Python 中实现以下逻辑。
# Variable i = loop (1 to 32)
days = dict()
if i in days: # if there's already a Key in the dict
variable_time = str(days[i])
hours_time = variable_time .split(':')[0]
minutes_time = variable_time .split(':')[1]
# It should sum the current value to the new value
time_horizontal = timedelta(hours=int(hours_time), minutes=int(minutes_time))
total_horizontal[i] = time_horizontal + timedelta(hours=int(hours_), minutes=int(minutes_))
else:
# otherwise, it will insert the default values
total_horizontal[i] = timedelta(hours=int(hours_), minutes=int(minutes_)) # this will get info from other variables
使用此代码,我收到以下错误:
例外:意外的数据类型类型“datetime.timedelta”
我该如何解决?谢谢。