Python3不支持的操作数类型 - :' list'和' datetime.date'

时间:2018-04-23 13:16:49

标签: python tkinter

错误: Python3不支持的操作数类型 - :' list'和' datetime.date'

代码:

from tkinter import Tk, Canvas
from datetime import date, datetime

def get_events():
    list_events = []
    with open('events.txt') as file:
        for line in file:
            line = line.rstrip('\n')
            current_event = line.split(',')
            event_date = datetime.strptime(current_event[1], '%d/%m/%y').date()
            current_event[1] = event_date
            list_events.append(current_event)
    return list_events

def days_between_dates(date1, date2):
    time_between = str(date1-date2)
    number_of_days = time_between.split(' ')
    return number_of_days[0]
root = Tk()

c = Canvas(root, width=800, height=800, bg='black')
c.pack()
c.create_text(100, 50, anchor='w', fill='orange', \
              font='Arial 28 bold underline', text='My Countdown Calendar')

events = get_events()
today = date.today()

for event in events:
    event_name = event[0]
    days_until = days_between_dates(events[1], today)
    display = 'It is %s days until %s' % (days_until, event_name)
    c.create_text(100, 100, anchor='w', fill='lightblue', \
                  font='Arial 28 bold', text=display)

events.txt文件

周年纪念,26/04/18生日,14/06/18最后一天的学校,04/05/18 圣诞25 /一十八分之一十二

1 个答案:

答案 0 :(得分:-1)

你有一个简单的拼写错误 - 当你的意思是events[1]时,你正在做event[1]