I'm trying to calculate a field based on the values of others in the same layer in a calculation. I can't work out why its not working. I've even cut everything down to just be based on one field and even that won't work, so frustrating!
This is based on one field
rows = arcpy.UpdateCursor(inputFC)
for row in rows:
val = row.getValue(Infield1)
row.setValue(outfld , val)
rows.updateRow(row)
del rows, row
arcpy.AddMessage("Completed")
this is the final script. Its meant to calculate calories based on minutes, speed and weight (weight as a number you input rather than a field) import sys, arcpy, math
inputFC = arcpy.GetParameterAsText(0) # Input feature class
timeField = arcpy.GetParameterAsText(1) # Input time in minutes
speedField = arcpy.GetParameterAsText(2) # Input speed
SlopeField = arcpy.GetParameterAsText(3) # Input Slope
weight = float(arcpy.GetParameterAsText(4)) #input weight in kg
arcpy.AddField_management(inputFC, 'Calories', 'LONG') #create calorie field
rows = arcpy.UpdateCursor(inputFC)
for row in rows:
time = row.getValue(timeField)
speed = row.getValue(speedField)
slope = row.getValue(SlopeField)
calories = time * (speed * 3.5 * weight)/200 * slope
row.setValue('Calories', calories)
rows.updateRow(row)
del row, rows
this says completed but the calories field ends up being null
del row, rows
should not be indented in the code as written. Right now you're deleting the cursor in the first iteration.