我有一个关于在python中从列表中访问对象类的问题,我已经将我的案例与堆栈溢出问题进行了比较,但是没有成功。我提出的问题如下
from datetime import *
class Booking:
def __init__(self):
self.year = int(input("Enter the Year: "))
self.month = int(input("Enter the Month: "))
self.day = int(input("Enter the Day: "))
self.start_date = datetime.now()
self.end_date = datetime(self.year, self.month, self.day)
booking(list)
来存储Booking
类的对象,该类在Room
类初始化时初始化李>from abc import *
from booking import Booking
class Room(ABC):
bookings = []
def __init__(self, price, capacity):
self.booking = Booking()
self.price = price
self.capacity = capacity
self.bookings.append(self.booking)
@abstractmethod
def is_booked(self, start_date, end_date):
pass
SingleBed
继承{from room import Room
class Singlebed(Room):
def __init__(self):
super(Singlebed, self).__init__(150, 2)
def is_booked(self, start_date, end_date):
if start_date >= end_date:
print("EndDate must be greater than StartDate")
is_Booked = False
for check_booking in self.bookings:
is_Booked = check_booking... (I wants to access objects.end_date in class Booking is saved in bookings)
single1 = Singlebed()
single2 = Singlebed()
single3 = Singlebed()
single4 = Singlebed()
single5 = Singlebed()
您正在迭代self.bookings,因此“check\u booking”是您的预订实例,包含属性start\u date、end\u date、year、month、day
相关问题 更多 >
编程相关推荐