3
我卡住了。看起來這一天似乎被某個地方的int所覆蓋。但是哪裏?一天成爲一個整數在哪裏?date.day()返回TypeError:'int'對象不可調用
from datetime import *
start_date = date(1901, 1, 1)
end_date = date(2000, 12, 31)
sundays_on_1st = 0
def daterange(start_date, end_date):
for n in range(int ((end_date - start_date).days)):
yield start_date + timedelta(n)
for single_date in daterange(start_date, end_date):
# type(single_date) => <type 'datetime.date'>
# type(date.day()) => TypeError: 'getset_descriptor' object is not callable
# type(single_date.day()) => TypeError: 'int' object is not callable
# ಠ_ಠ
if single_date.day() == 1 and single_date.weekday() == 6:
sundays_on_1st += 1
print sundays_on_1st
請*包含追蹤;如果沒有它,很難猜測錯誤可能在哪裏。 – 2013-04-08 18:06:31