2013-04-25 69 views
0

我有這個電梯任務,我卡在1個地方。我有一個建築物,裏面有客戶名單。我試圖讓客戶進入電梯的方法 - 客戶被追加到電梯列表中,但無法找到將客戶從建築物清單中刪除的方法:嘗試使用dellist.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 

回答

0

你好這裏是一些我的建議:

1)建築應該有N層內,你可以有一個buildingFactory創建有n層大樓。

def createBuilding(self, N): 
    return building = Building(N) 
class Building: 
    def __init__(self, N): 
     self.floorWatingList= [] 
     for f in range(N): 
      self.floorWaitingList.append() = [] 

2)使用clear()或彈出()方法從列表中刪除客戶

for c in building.floorWaitingList[current]: 
     elvator.enter(c) 
building.floorWaitingList.clear()