python object has no attribute_如何修复python中的“AttributeError:type object has no attribute”?...
您的代碼引發此異常:
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.
總結
以上是生活随笔為你收集整理的python object has no attribute_如何修复python中的“AttributeError:type object has no attribute”?...的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python作者 google面试_如果
- 下一篇: 运营管理最新版史蒂文森_运营增长人都在看