Can you help me with my code below to delete/send multiple ObjectIDs to a delete parameter?

Currently the code just finds one record and send that Object ID to the delete paramter, but id like to be able to select a certain value in a attribute field and delete all or setup some sort of For or While Loop to pass all Object IDs to the delete paramter. One of the field names is 'Biologist' and a test record/value for the example is 'jah'.

from arcgis.gis import GIS
from IPython.display import display

gis = GIS(username="xxx", password="xx")

search_result = gis.content.search('test url')

test_item = search_result[1]
test_layers = test_item.layers

test_fset = test_layers[0].query()

test_flayer = test_layers[0]

test_features = test_fset.features

remove_feature = [f for f in test_features if f.attributes['Biologist'] == 'jah'][0]
dele = remove_feature.get_value('OBJECTID')

delete_result = test_flayer.edit_features(deletes=str(dele))

1 Answer 1


The edit_features function expects a comma-separated list of object ids for the deletes argument. See https://esri.github.io/arcgis-python-api/apidoc/html/arcgis.features.toc.html#arcgis.features.FeatureLayer.delete_features for documentation.

The following should work:

remove_features = [f for f in test_features if f.attributes['Biologist'] == 'jah']
object_ids = [f.get_value('OBJECTID') for f in remove_features]
object_ids_str = ",".join(object_ids)
delete_result = test_flayer.edit_features(deletes=object_ids_str)

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.