-6

次のロジックを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

このコードでは、次のエラーが発生します。

例外: 予期しないデータ型 type 'datetime.timedelta'

どうすれば解決できますか?ありがとう。

4

1 に答える 1

-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_)))
于 2013-09-18T10:55:31.840 に答える