I am having some problems retrieving data from a dictionary that is created in a for loop. In my code I have two dictionaries created and updated periodically, one from a machine database and one from a global database. The problem I am having is that i need to evaluate each of them in a separate for loop based on machine number. I can create the dictionaries no problem, but I am struggling with the code to retrieve a different dictionary tag per iteration of the for loop.
This is the code that creates the dictionaries:
# sets machines that need error checking performed
workcenters = ['25294', '25296', '25331', '25334', '25335', '25336']
# Queries local machine database
for index in range(len(workcenters)):
result = EEDBConnect.connect(workcenters[index])
globals()["a" + str(workcenters[index])] = result
# Returns a different dictionary for each machine in the form of:
a25294 = {'Line_Status':None, 'Order_ID':None}
a25296 = {'Line_Status':None, 'Order_ID':None}
a25331 = {'Line_Status':None, 'Order_ID':None}
ect....
ect....
# Queries global machine database
for index in range(len(workcenters)):
result = GBDBConnect.connect(workcenters[index])
globals()["b" + str(workcenters[index])] = result
# Returns a different dictionary for each machine in the form of:
b25294 = {'Line_Status':None, 'Order_ID':None}
b25296 = {'Line_Status':None, 'Order_ID':None}
b25331 = {'Line_Status':None, 'Order_ID':None}
ect....
ect....
Now the part I am having issues with, how do I go about looking up those dictionaries in a for loop? Below is just an example in code of what I am trying to do.
(I know it is completely the wrong way to write it but i can't find a better way to describe it)
****** Updated ******
for index in range(len(workcenters)):
a = #here is where i need to assign the a##### dictionary
b = #here is where i need to assign the b##### dictionary
stat[str(workcenters[index])] = a['Line_Status'] == b['Line_Status']
ordr[str(workcenters[index])] = a['Order_ID'] == b['Order_ID']
I have tried multiple ways to get the desired result and I have been stuck on this problem for about a week now. I'm sure it is something really stupid that I am missing, but I just started writing python this year for this project and any help would be greatly appreciated. Thanks!