NameError:在封闭范围内分配之前引用的自由变量“入站”

问题描述 投票:0回答:0

我之前已经定义并运行了所有参数(inbound、dockcapacity)。但是,当我尝试编写以下函数的代码时,出现错误。有人可以建议我解决它的方法吗?

NameError: free variable 'inbound' referenced before assignment in enclosing scope

TimeWindow=100
door1=Door(id=1,typeDoor='inbound',assignList=TimeWindow*[0])
door2=Door(id=2,typeDoor='inbound',assignList=TimeWindow*[0])
inbound=[door1,door2]
DockCapacity=TimeWindow*[2000]

def ScheduleBySequence(truckInfo,TimeWindow,sequenceList):
    receiveTruckList=truckInfo.loc[(truckInfo['TruckType'] == 'inbound'),'TruckName'].values.tolist()

    for i in range(1,len(truckInfo.index)+1):
        truckCandidate=truckInfo.loc[truckInfo['Status']==0,'TruckName'].values.tolist()
        truckFunction=truckInfo.loc[truckInfo['Status']==0,'TruckType'].values.tolist()
        if len(truckCandidate)==0:
            break
    
    def SoonestDoorSatified(truckFunction):
        inb1=[]
        inb2=[]
        if truckFunction[0]=='inbound':
            for ind in inbound:
                for t in range(considerTime,TimeWindow):
                    if (ind.id==1) and (ind.assignList[t]<=0):
                       inb1.append(t)
                    if (ind.id==2) and (ind.assignList[t]<=0):
                       inb2.append(t)
            return min(inb1[0], inb2[0])
          .....
python function enclose
© www.soinside.com 2019 - 2024. All rights reserved.