I am sorry but seems you only posted half your code and I don’t follow what you try to do without more context. Let me see if I follow:
You loop over a List with Dictionaries
for each Dictionary1 you have a Matching_Value
you Try to find this Matching_Value in Dictonary2
If you find a value you do something with it
If you the Matching_Value does not exist, you get an error and this triggers the Except?
As a first tip: Try to avoid Try-Except statements as much as possible, because: If something goes wrong, you don’t get an error, because Python catches these for you.
Second tip: If you cannot avoid them, always Print the Error!
#not a practical way of debugging
try:
DoSomething()
except:
print("There is an error")
#A better way of Debugging
try:
DoSomething()
except Exception as exception:
print("There is an error: " + exception.Message)
This way, if there is an error, you see what the error says and you can fix it. In the screenshot below you can see how you can do this in Dynamo. Mind the Namespaces
Since I only got half of the python code, I copied you code and placed comments after the lines.
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])
tester.append("test if this runs at start")
#test.append(parameter_key_tomatch)
#test.append(Matching_Value)
try: #this Try will never fail. I'll Call this Try 1
try: #I will call this Try 2
print ("here")
Get_Matching_Value_LongIndex = Base_MatchingWalls_Dict[Matching_Value] #This could already trigger you Try2 Except2 because "Matching_Value" does not Exist in "Base_MatchingWalls_Dict".
Split_Index = Get_Matching_Value_LongIndex.split(indexplacesplit)[1] #This one will always fail, because "indexplacesplit" does not Exist in the current context
MatchedWall = Base_MatchingWalls[int(Split_Index)] #This can fail if "Split_Index" is not a number
tester.append(Matching_Value)
tester.append(MatchedWall)
except: #I will call this Except 2
tester.append(Matching_Value)
#tester.append("here")
print ("here")
tester.append("test if this runs at end") # this will never fail, so Except 1 will never get triggered
except: #I will call this Except 1
tester.append(Matching_Value)
print ("here")
You can deal with most of the errors in the code in other ways. e.g. if you want to check if a certain value exists in a dictionary, you can do it like below, instead of Trying to find it and if it doesn’t exist it returns an error.
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])
tester.append(Matching_Value)
# you want to check if "Matching_Value" exists in the Dictionary "Base_MatchingWalls_Dict"
if Base_MatchingWalls_Dict.Keys.Contains(Matching_Value):
Get_Matching_Value_LongIndex = Base_MatchingWalls_Dict[Matching_Value]
Split_Index = Get_Matching_Value_LongIndex.split(indexplacesplit)[1] #This one will always fail, because "indexplacesplit" does not Exist in the current context
MatchedWall = Base_MatchingWalls[int(Split_Index)] #This can fail if "Split_Index" is not a number
tester.append(MatchedWall)
else:
#Well "Matching_Value" does not exist in "Base_MatchingWalls_Dict"
print("The Matching_Value did not Exist in the Base_MatchingWalls_Dict")
pass
Sorry for the long awnser!