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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值