[GIS] How to ascertain if a cell/field contains a value in ArcGIS attribute table

arcgis-10.0arcpypython

I have done a bit of research on this but can't seem to find an answer. I am wondering if there is a way to identify whether a cell/field in the ArcGIS attribute table contains a value using the search cursor. Initially, I thought it would be as simple as this:

arcpy.MakeFeatureLayer_management(node110, "node_layer12")
arcpy.SelectLayerByAttribute_management ("node_layer12", "NEW_SELECTION", query1)

rows = arcpy.SearchCursor("node_layer12")
for row in rows:
        link_id2 = row.getValue("DRN_link")

if link_id2 == "E*":
    print "YES"

unfortunately this didn't work. I knew that if the field I was searching had a value it would start with an 'E' so I thought a wildcard might work. Obviously not. Any ideas?

Please note. I only have access to arcgis 10 so can't use the arcpy.da.searchcursor.

Best Answer

Your script is currently only checking the last value it gets in link_id2. To check every value of link_id2 (and presumably do some operation if it matches the condition) embed the conditional within the loop.

You can use the python .startswith() function to check for strings starting with the letter "E":

for row in rows:
    link_id2 = row.getValue("DRN_link")
    if link_id2.startswith("E"):
        print "YES"

If you are checking whether many (dozens or more) rows meet a particular condition, you can instead count them:

counter = 0
for row in rows:
    link_id2 = row.getValue("DRN_link")
    if link_id2.startswith("E"):
        counter += 1
print counter