I am trying to use an update cursor and receiving an error. I'm not very familiar with using cursors, so please bear with me. I am trying to write a 1 or 0 to a field, based on a condition. The error I am receiving is:
IndexError: list assignment index out of range.
I have googled around and have seen solutions, but I'm still not understanding why its throwing an error.
#Define Environments rasters = r"C:\Data.gdb" points = r"C:\Data.gdb\Points" #Set workspace arcpy.env.workspace = rasters arcpy.env.overwriteOutput = True # Get a list of the rasters in the workspace rasters = arcpy.ListRasters() # Loop through the list of rasters for inRaster in rasters: print str("Processing " + inRaster) rastername = str(inRaster) fieldname = str(inRaster + "_perf_flag") # Add surface information to Well FC arcpy.AddSurfaceInformation_3d(points,inRaster , "Z", "LINEAR") print "Formation Depth Added" # Create positive values from SS values arcpy.CalculateField_management(points, "Z", '!Z!*-1', "PYTHON") print "Depth Values Made Positive" # Add new field name for perf flag arcpy.AddField_management(points, fieldname, "LONG", 9, "", "", fieldname, "NULLABLE", "NON_REQUIRED") print "Flag Field Added" # Raname Z field as formation grid name arcpy.AlterField_management(points, 'Z', rastername, rastername) print "Field Altered" # Calculate if well was perfed in the formation - Flag 1 as yes - Flag 0 as no with arcpy.da.UpdateCursor(points, ["Base", "Top",rastername, fieldname]) as cursor: for row in cursor: if (row >= row and row <= row): row = 1 if not (row >= row and row <= row): row = 0 cursor.updateRow(row) print "Processing perf flags for " + rastername