0
我有這個電梯任務,我卡在1個地方。我有一個建築物,裏面有客戶名單。我試圖讓客戶進入電梯的方法 - 客戶被追加到電梯列表中,但無法找到將客戶從建築物清單中刪除的方法:嘗試使用del
和list.remove(item)
,但沒有歡樂。任何人都可以指出我正確的方向嗎?從python列表中刪除對象實例
class building(object):
def __init__(self, floors = 0, customerNo = 0,):
self.floors = 0
self.myE = elevator()
self.customerNo = 0
self.customersWaiting = []
self.customersTransported = []
def initCustomers(self):
cnt = 1
cust = cnt
while cnt <= myB.customerNo :
floor = random.randint(0, self.floors - 1)
destination = random.randint(0, self.floors - 1)
cust = customer(cnt, floor , destination)
self.customersWaiting.append(cust)
cnt +=1
class customer(object):
def __init__(self,cnt, floor = 0, destination = 0):
self.cnt = cnt
self.floor = floor
self.destination = destination
def enterElevator(self):
for cust in myB.customersWaiting :
if myB.myE.lvl == self.floor :
myB.myE.customersIn.append(self)
#del cust(self)
#myB.customersWaiting.remove(self)
else:
pass