0

I'm trying to check the "fiberEquipment" table against the "material_cd" table and find instances where there are discrepancies. E.G -- Checking that "material_cd" 10785823 in "fiberEquipment" has all the correct values associated with it (inputportcount, outputportcount, inputblockcount, etc.) per the "material_cd" table.

enter image description here

The code I'm using below takes the values from the "fiberEquipment" table, inserts them into a dictionary and than uses a search cursor invoking the dictionary elements to check for discrepancies. The code currently works without any errors, but the logic seems to be flawed, as it's not doing anything when all fields match.

# Fiber Equipment/Material Catalog fields
matcd_fields = ["material_cd", "inputportcount"]
fibequip_fields = ["material_cd", "inputportcount", "outputportcount", "inputblockcount", "outputblockcount", "objectid"]

# Compare FIBEREQUIPMENT table to Material Catalog table and determine which objectid's have records that aren't matching
 ipc = {} # 'material_cd' : 'inputportcount'
 ipcOID = {} # 'material_cd' : 'objectid'
 opc = {} # 'material_cd' : 'outputportcount'
 opcOID = {} # 'material_cd' : 'objectid'
 ibc = {} # 'material_cd' : 'inputblockcount'
 ibcOID = {} # 'material_cd' : 'objectid'
 obc = {} # 'material_cd' : 'outputblockcount'
 obcOID = {} # 'material_cd' : 'objectid'

with arcpy.da.SearchCursor(fiberEquipment, fibequip_fields) as cursor:
    for row in cursor:
        ipc[str(row[0])] = row[1]
        ipcOID[str(row[0])] = row[5]
        opc[str(row[0])] = row[2]
        ipcOID[str(row[0])] = row[5]
        ibc[str(row[0])] = row[3]
        ibcOID[str(row[0])] = row[5]
        obc[str(row[0])] = row[4]
        obcOID[str(row[0])] = row[5]

objectID = []

with arcpy.da.SearchCursor(material_catalog, matcd_fields) as cursor:
    for row in cursor:
        if ipc[str(row[1])] == row[1]:
             objectID.append(ipcOID[row[0]])
2
  • 1
    matcd_fields only has one field name in it so row must be row[0]
    – Hornbydd
    Commented Jan 29, 2019 at 18:57
  • I forgot to add the addition into the post here, but I have it in my code. Getting the same error.
    – GIS_GOD
    Commented Jan 29, 2019 at 19:00

1 Answer 1

3

It is this line that is flawed:

if row[0] == ipc[str(row[0])]:

This is essentially asking if 10785823 = 24 which obviously it does not!

I believe you are trying to ask if the dictionary ipc contains 10785823? So your test should be:

if ipc.has_key(str(row[0]):
    objectID.append(ipc[row[5]])

You are not storing the "objectid" from fiberEquipment in a separate dictionary, you need to add some code to do that, then this line objectID.append(ipc[row[5]]) becomes something like objectID.append(YOURobjectIDdictionary[row[0]])

2
  • 1
    @GIS_GOD see edit to my answer. But you already knew that... ;)
    – Hornbydd
    Commented Jan 29, 2019 at 17:14
  • Using your advice I edited the code above, but am getting the error KeyError: '24' on the 2nd to last line of code now, any idea what the issue is?
    – GIS_GOD
    Commented Jan 29, 2019 at 18:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.