我正在尝试用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'
我该如何解决?感谢。
答案 0 :(得分:-1)
解决了
# Variable i = loop (1 to 32)
days = dict()
if i in days:
variable_time = str(days[i])
hours_time = variable_time .split(':')[0]
minutes_time = variable_time .split(':')[1]
time_horizontal = timedelta(hours=int(hours_time), minutes=int(minutes_time)) + timedelta(hours=int(hours_), minutes=int(minutes_))
total_horizontal[i] = str(time_horizontal)
else:
# otherwise, it will insert the default values
total_horizontal[i] = str(timedelta(hours=int(hours_), minutes=int(minutes_)))