I am following the example within Editing Features: to select a feature within the feature layer.
sfo_feature = [f for f in ports_features if f.attributes['port_name']=='SAN FRANCISCO'][0]
The code is successful when hard-coding the value, as with 'SAN FRANCISCO' above, but fails with IndexError: list index out of range when using a variable. Following is my code:
The following is successful:
obs_feature = [f for f in obs_features if f.attributes['globalid']=='18d8c3ac-f828-4d93-b4e8-8a3b281f1790'][0]
And, the following is successful:
globalid = '18d8c3ac-f828-4d93-b4e8-8a3b281f1790'
obs_feature = [f for f in obs_features if f.attributes['globalid']==globalid][0]
The following fails, with IndexError: list index out of range when using a variable. I know the value is correct via the use of AddMessage to know the value being queried:
globalid = "'"+original_globalid+"'"
arcpy.AddMessage("globalid: {}".format(globalid)+"; fld: {}".format(fld)+"; fld_value: {}".format(fld_value))
obs_feature = [f for f in obs_features if f.attributes['globalid']==globalid][0]
I assume this is something simple, but can't figure out the problem. I've tried format(globalid), although that shouldn't be necessary, but that fails as well.
Someone, please save me from myself!