1

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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Feb 12, 2018 at 1:39
7
  • 2
    Try using a with block for your cursor. Is your feature class participating in a topology or geometric network? Is your FULL_NAME a text field or numeric? if it's numeric you will need to specify if row[0] == 1: (no quotes) C:/hwy doesn't look like a feature class name, should it be c:/hwy.shp? Commented Feb 12, 2018 at 1:51
  • 1
    Wouldn't creating a feature layer and feeding that into a DeleteFeatures be more efficient? Commented Feb 12, 2018 at 1:59
  • Is the field containing 1 a string or integer field? Commented Feb 12, 2018 at 2:02
  • 1
    1 is a string the hwy is actually in a geodatabase I just simplified the naming for the demo Commented Feb 12, 2018 at 2:17
  • 1
    I would be interested in seeing a benchmark on the DeleteFeatures method vs the UpdateCursor approach. Commented Feb 12, 2018 at 2:31

1 Answer 1

3

Instead of:

 row[0] == "1": 
 cursor.deleteRow()

try this:

 if row[0] == "1": 
 cursor.deleteRow()
answered Feb 12, 2018 at 1:50
3
  • This did not change anything Commented Feb 12, 2018 at 2:31
  • 1
    @user10720 Try refreshing your table to see if the changes took effect. Commented Feb 12, 2018 at 2:37
  • 3
    Great, two things: 1) consider wrapping your cursor in a with 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. Commented Feb 12, 2018 at 2:51

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.