3
我想在函數中執行一些日期算術。TypeError:不支持的類型爲timedelta天組件:datetime.datetime
from datetime import datetime, timedelta
def foo(date1, summing_period):
current_period_start_date = date1 - timedelta(days=summing_period)
# Line above causes the error:
# TypeError: unsupported type for timedelta days component: datetime.datetime
第一個參數是一個日期OBJ和2 arg是一個整數
是什麼原因造成這個錯誤,以及如何解決它?
顯然你的第二個參數是* not *一個整數。 – 2012-07-24 11:07:50