for循环中的Try语句不起作用

2024-10-01 05:06:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的脚本,我发现如果我的Try语句满足,第一个循环的整个迭代将结束,它将进入下一个循环迭代

我想做的是,如果语句得到满足,它就会返回到它所在的for循环中的elif

所以基本上我想去

  1. 循环

  2. 然后,如果有什么办法奏效,就试试看(我知道有些办法行不通)

  3. 然后返回for循环(所有后续循环仍然有效。

理想情况下,我会将其结构为:for-loop-try语句-for-loop,但本质上我问的问题与发生这种情况时相同,循环也会爆发

谢谢你,山姆

# LOOP OVER THE DICTIONARIES (CSV LINE DATA) AND PULL UP THE PARAMETER KEY TO MATCH

tester = []

updatefamilyname = IN[6]
typename_input01_value = IN[7]
typename_input02_value = IN[8]

for datarow_dict in Data_DictionaryList:


    # Get matching value from data row dictionary

    Matching_Value = str(datarow_dict[parameter_key_tomatch])
    #test.append(parameter_key_tomatch)
    #test.append(Matching_Value)

    try: 
        Get_Matching_Value_LongIndex = Base_MatchingWalls_Dict[Matching_Value]
        Split_Index = Get_Matching_Value_LongIndex.split(indexplacesplit)[1]
        MatchedWall = Base_MatchingWalls[int(Split_Index)]
        #test.append(MatchedWall)
        #test.append("here2")

        for para_key, para_value in datarow_dict.items():
            #ResultOutput.append(para_key)
            #ResultOutput.append(typename_input01_value)
            #test.append(para_key)
            #test.append(para_value)

            # We then say if the paramter key is the same as the matching key, open the following
            if para_key == parameter_key_tomatch:
                #test.append("inside")
                ResultOutput.append(para_key + " equal to " + para_value)

                # Set New Family Type Name Value                
                #if para_key == typename_input01_key:
                    #typename_input01_value = para_value
                    #tester.append("inside link")

                #elif para_key == typename_input02_key:
                    #typename_input02_value = para_value

                #else:
                    #print ("go")

            elif para_key != parameter_key_tomatch:
                ResultOutput.append(para_key)   
                print ("not here")
                #ResultOutput.append(para_key)  
                #TestParameter_ = testparavalue(MatchedWall, para_key, para_value)      

                #else:
                    #pass

            # We then say, if its not the same, this is when we want to do some things, could be where we change the family name if we change the name of the name and number
            else:
                print ("ouside exception")
                #ResultOutput.append("else why")

    if updatefamilyname == "Yes":
        ResultOutput.append("update name accepted")     
        print ("yes")



        # THIS IS WHERE WE COULD PASS IN THE OTHER ONE TO MATCH TO FORM THE CHANGE IN FAMILY TYPE NAME


            #typename_input01_value
            #typename_input01_value
            # This is where we bring in 

    # Anything where matching para does not have a corresponding wall type
    except:
        print ("here")
        ResultOutput.append(Matching_Value)

Tags: thekeyintestforifvalueprint