Hello,
I´m trying to work my way through the ´GIS Tutorial for Python Scripting´ by David Allen. Working with cursors (Tutorial 2.3) is giving me a hard time as there seem to be a number of ways to approach this subject, but I can´t make any sense of them. What confuses me most is the numbering in the syntax. Can anybody helmp me with Exercise 2.3? The problem seems to be a non-defined cursor name, but I´m lost here. This is the code I´ve come up with so far:
import arcpy
from arcpy import env
env.workspace = r"C:\EsriPress\GISTPython\Data\City of Oleander.gdb"
env.overwriteOutput = True
updateFC = "StreetLights"
with arcpy.da.UpdateCursor("StreetLights",["TYPE", "Buffer"]) as cursor:
for row in cursor:
TYPE = row[0]
Buffer = row[1]
if TYPE == "MV":
Buffer = 125
else:
Buffer = 200
cursor.updateRow(row)
print "All done updating"
del cursor
del row
Solved! Go to Solution.
A few errors in the code.
import arcpy from arcpy import env env.workspace = r"C:\EsriPress\GISTPython\Data\City of Oleander.gdb" env.overwriteOutput = True updateFC = "StreetLights" with arcpy.da.UpdateCursor(updateFC, ["TYPE", "Buffer"]) as cursor: for row in cursor: TYPE = row[0] if TYPE == "MV": row[1] = 125 else: row[1] = 200 cursor.updateRow(row) del cursor, row
A few errors in the code.
import arcpy from arcpy import env env.workspace = r"C:\EsriPress\GISTPython\Data\City of Oleander.gdb" env.overwriteOutput = True updateFC = "StreetLights" with arcpy.da.UpdateCursor(updateFC, ["TYPE", "Buffer"]) as cursor: for row in cursor: TYPE = row[0] if TYPE == "MV": row[1] = 125 else: row[1] = 200 cursor.updateRow(row) del cursor, row
Hello Xander,
thanks for your clear explanation, this is very helpful.
Eric