Select to view content in your preferred language

Update Cursor NameError

1001
3
Jump to solution
02-25-2019 06:38 AM
PaulStephenson
Frequent Contributor

I have a script that has worked without issues when running against a file gdb, but am struggling to understand why it is not compatible as is for use with SQL gdb.

The error I get is
...line 31, in <module> cursor.updateRow(row)
NameError: name 'cursor' is not defined

# Import system modules
import arcpy
from arcpy import env


# Set workspace and declare variables
workspace = env.workspace = r'Database Connections\mysql.default.sde'

fc = 'Ramps_Copy'
fields = ['BusStopsValue', 'City_and_PubValue', 'Commercial_ZoningValue', 'MedicalValue',
          'Parks_RecValue', 'SchoolsValue', 'Social_ServValue', 'Ped_CollisionsValue']

# Start edit session
edit = arcpy.da.Editor(workspace)
edit.startEditing(False, True)
edit.startOperation()


# Set values to update
with arcpy.da.UpdateCursor(fc, fields) as cursor:
    for row in cursor:
        # Assign values to categories
        row[0] = arcpy.GetParameterAsText(0)  # Bus Stops
        row[1] = arcpy.GetParameterAsText(1)  # City & Public Facilities
        row[2] = arcpy.GetParameterAsText(2)  # Commercial Zoning
        row[3] = arcpy.GetParameterAsText(3)  # Medical Facilities
        row[4] = arcpy.GetParameterAsText(4)  # Parks & Rec
        row[5] = arcpy.GetParameterAsText(5)  # Schools
        row[6] = arcpy.GetParameterAsText(6)  # Social Services
        row[7] = arcpy.GetParameterAsText(7)  # Pedestrian-Related Collisions
        cursor.updateRow(row)

        # Cleanup
        del row
        del cursor


# Stop edit sesion
edit.stopOperation()
edit.stopEditing(True)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

Any thoughts?

Paul

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

Not sure if it is a copy/paste artifact, but Line #35 outdented.  You are deleting the cursor after the first record.  Does that fix it?

View solution in original post

3 Replies
JoshuaBixby
MVP Esteemed Contributor

Not sure if it is a copy/paste artifact, but Line #35 outdented.  You are deleting the cursor after the first record.  Does that fix it?

PaulStephenson
Frequent Contributor

Thanks for the second set of eyes Joshua. I bet you're right, will give it a shot this evening. Not sure but it may have been like this yet still running against the file gdb...will look at that as well.

0 Kudos
PaulStephenson
Frequent Contributor

Indeed that was it. I must have bumped that bit in at some point without realizing it and was looking at everything but that.

Thanks again, much appreciated.

0 Kudos