This is my first post, so any help is greatly appreciated. I'm trying to use an update cursor to calculate a field. Basically, I'm trying to avoid division by 0 by looking in row and see if it's 0. My code thus far is:
import arcpy fc="C:/Temp/crimeGrid.shp" fields=('MEAN_GRIDC', 'SUM_Join_C', 'crimeRate') with arcpy.da.UpdateCursor(fc,fields) as cursor: for row in cursor: if (row > 0): row = row/row else: row = 0 cursor.updateRow(row)
Any ideas or help on what I'm missing? I can only assume (yes I know what assuming does) that it's the calculation aspect of my code. Thanks!!!
UPDATE: Sorry for the ridiculous question. I continually thought it was in the division of rows, so I looked into my fields a little closer. Turns out, Row and Row were Double and Row was Long. Fixed that aspect and the code works as is.