# Name: DeleteRows_Example2.py
# Description: Delete rows from a table based on an expression
# Import system modules
import arcpy
# Set environment settings
arcpy.env.workspace = "C:/data"
# Set local variables
inTable = "accident.dbf"
outTable = "C:/output/new_accident.dbf"
tempTableView = "accidentTableView"
expression = arcpy.AddFieldDelimiters(tempTableView, "Measure") + " = 0"
# Execute CopyRows to make a new copy of the table
arcpy.CopyRows_management(inTable, outTable)
# Execute MakeTableView
arcpy.MakeTableView_management(outTable, tempTableView)
# Execute SelectLayerByAttribute to determine which rows to delete
arcpy.SelectLayerByAttribute_management(tempTableView, "NEW_SELECTION",
expression)
# Execute GetCount and if some features have been selected, then execute
# DeleteRows to remove the selected rows.
if int(arcpy.GetCount_management(tempTableView)[0]) > 0:
arcpy.DeleteRows_management(tempTableView)