我有一个房间类。我希望每次使用该类创建对象时,该对象都会添加到所有房间的列表中。客房等级:
class Rooms:
"""Room class, takes type,days, occupied or not and when it frees up"""
def __init__(self, room_type, days, occupied, when_free):
self.room_type = room_type
self.days = days
self.occupied = occupied
self.when_free = arrow.get(when_free,'YYYY-MM-DD')
任何其他反馈也很感激!
也不确定我是否应该为此创建新主题,但是否有可能在创建对象并将 True onoccuped 传递给对象时,您不需要传递第 4 个变量,而是将其作为当前日期?简而言之,如果没有第四个变量,它会通过 arrow.get(str(arrow.utcnow()),'YYYY-MM-DD')
想出了我的第二个问题。我确实将init更改为:
def __init__(self, room_type, days, occupied, when_free=str(arrow.get(str(arrow.utcnow()),'YYYY-MM-DD'))):
self.room_type = room_type
self.days = days
self.occupied = occupied
self.when_free = arrow.get(when_free,'YYYY-MM-DD')