避免在Python中嵌套For循环

时间:2019-12-11 02:06:01

标签: python-3.x for-loop

我对无法考虑开箱即用的情况的想法感到困惑。我正在实施一个设备自动化脚本,在其中使用GPIB conn(PyVisa)与这些设备进行交互,

我有一个配置文件,该文件定义了要在循环中使用的以下三个列表的长度, Total_subDie_cnt = 5

#Loop Through all SubDie
for subdie in range(int(confObj.get('Total_Subdie'))):
    print('\tTesting SubDie Num : ', str(subdie))
    if (subdie > 0):
        #Move to the First/Next SubDie only if not at the First SubDie
        Prob.moveSubDie(subdie) #Sending Command to Equipment via Prob Module

    for x in range(confObj.get('Structure_Cnt')):
        struc = str(parseObj.struc_type[x]) #Get Structure Type of current structure
        struc_name = str(parseObj.struc_name[x]) #Get Structure Name of current structure
        module_list = module_table.get(struc).split(',') #Get Total Number of module count for current structure
        Prob.moveStructure(parseObj.struc_X[x], parseObj.struc_Y[x]) # Move to current strcuture Location via Prob Module

        for y in range(len(module_list )):
            Prob.moveOpticalSubDie(module_list[y]) #Move to specific module
            #After moved to required location Measurement is performed

当涉及到第二个FOR循环时,我有一个列表,该列表捕获了循环中当前结构的名称(例如)structure_Name [structure],并根据structure_Name决定要在其中使用的Total_module_cnt值。第三个FOR循环。

关于如何加快此过程的任何建议,目前随着每个计数范围的增加,它占用了过多的x y z。

谢谢

0 个答案:

没有答案