0

I am trying to develop a script that searches for a particular ID in a user selected field. To this end I have used the select layer by attributes tool to search for a derived number in a field specified by the user.I cannot, however, after numerous attempts, get the where clause right. I have posted my latest attempt below:

import arcpy
from arcpy import env

work_space = "L:\\DRAINAGE\\D_GROUP6\\STAFF\\CJE\\EDRNb\\EDRN_holding.gdb"

env.workspace = work_space

arcpy.env.overwriteOutput = True

selected_li = "L:\\DRAINAGE\\D_GROUP6\\STAFF\\CJE\\EDRN_holding.gdb\\EDRN7\\EDRN_LINK"
OB_ID = "OBJECTID_1"

rows = arcpy.SearchCursor(selected_li)
for row in rows:
    id_LCC = row.getValue(OB_ID)
    id_TNDE = row.getValue("TO_DRNNODE")
    if id_TNDE == " " or id_TNDE == None:
        arcpy.MakeFeatureLayer_management(selected_li, "feature_layer10") 
        arcpy.SelectLayerByAttribute_management ("feature_layer10", "NEW_SELECTION", '"' + str(OB_ID) + '" =' + "'" + str(id_LCC) + "'")

So, if anyone has any ideas please do let me know.

1
  • 1
    To check for null you should use id_TNDE is None, not id_TNDE == None
    – artwork21
    Commented Jun 26, 2015 at 16:13

1 Answer 1

1

If we print out your formatted string we get this: '"OB_ID" =\'id_LCC\''

This is not what you want. Format considerations for file GDBS are as follows:

Use .format to simplify the variable substitution

The query format should be:

"{} = '{}'".format(OB_ID,ID_LCC)

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.