# Delete unnecessary attachments from a feature class using a match table
import arcpy
input = r"C:\Data\City.gdb\Parcels"
input_field = "OBJECTID"
match_field = "MatchID"
name_field = "Filename"
workspace = arcpy.Describe(input).path
# Create a new geodatabase Match Table for the RemoveAttachments tool
# to delete the designated attachments for the associated ObjectID and file name.
match_table = arcpy.management.CreateTable(workspace, "remove_matchtable")
arcpy.management.AddFields(match_table, [['MatchID', 'LONG'], ['Filename', 'TEXT']])
# Create a list to remove attachments pic1a.jpg and pic1b.jpg from feature 1,
# pic3.jpg from feature 3, and pic4.jpg from feature 4.
delete_list = [[1, "pic1a.jpg"], [1, "pic1b.jpg"], [3, "pic3.jpg"], [4, "pic4.jpg"]]
# Iterate through the delete list and write it to the Match Table.
with arcpy.da.InsertCursor(match_table, ['MatchID', 'FileName']) as match_cursor:
for row in delete_list:
new_row = row[0], row[1]
match_cursor.insertRow(new_row)
del match_cursor
# Use the match table with the Remove Attachments tool.
arcpy.management.RemoveAttachments(input, input_field, match_table, match_field, name_field)