I am trying to delete field names where the field "FULL_NAME" = 1.
What am I doing wrong here?
I am not getting an error message, but nothing is being deleted from my file. I am not sure why the delete field isn't working.
import arcpy
roads = "C:/hwy"
cursor = arcpy.da.UpdateCursor(roads, ["FULL_NAME"])
for row in cursor:
row[0] == "1":
cursor.deleteRow()
del row
del cursor
asked Feb 12, 2018 at 1:39
1 Answer 1
Instead of:
row[0] == "1":
cursor.deleteRow()
try this:
if row[0] == "1":
cursor.deleteRow()
answered Feb 12, 2018 at 1:50
-
This did not change anythinguser10720– user107202018年02月12日 02:31:15 +00:00Commented Feb 12, 2018 at 2:31
-
1@user10720 Try refreshing your table to see if the changes took effect.2018年02月12日 02:37:33 +00:00Commented Feb 12, 2018 at 2:37
-
3Great, two things: 1) consider wrapping your
cursor
in awith
statement as you see in the documentation (pro.arcgis.com/en/pro-app/arcpy/data-access/…) and 2) please consider accepting @PolyGeo's answer so we can consider this question resolved.2018年02月12日 02:51:38 +00:00Commented Feb 12, 2018 at 2:51
lang-py
DeleteFeatures
be more efficient?1
a string or integer field?