您的代码引发此异常:
AttributeError: type object 'Meeting' has no attribute 'datetime'
在这一行:
meeting_start = Meeting.datetime.start_time.hour
Python告诉您,Meeting类没有名为datetime的属性。这是真的:Meeting类是一个制造meeting对象的工厂(或实例),这些对象有start_time和end_time属性,可以这样访问:>>> meeting = Meeting(datetime(2018, 8, 1, 9, 0, 0), datetime(2018, 8, 1, 11,
0, 0))
>>> print(meeting.start_time)
2018-08-01 09:00:00
>>> print(meeting.end_time)
2018-08-01 11:00:00
正在向您的check_availability函数传递一个会议列表,因此您需要循环查看该列表,以检查是否有任何会议与建议的会议时间冲突。def check_availability(meetings, proposed_time):
# Loop over the list of meetings; "meeting"
# is the meeting that you are currently inspecting.
for meeting in meetings:
# if proposed_time is between meeting.start_time
# and meeting.end_time, return False
# If you get through the list without returning False
# then the proposed time must be ok, so return True.