SOLVED: although the field was not nullable (no null values), a glitch created one in the heading field, so the variable was stored as a null value and thus the NoneType.
I am using updateCursor to subtract a previous value (last direction) from a current value (direction) to populate a new field (change in direction). I borrowed and modified code from the forums (thanks anonymous contributors!) so while I understand the conditionals and what they all do, I did not write this myself.
import arcpy fc = r'...' rows = arcpy.UpdateCursor(fc) firstTime = True for row in rows: if firstTime: previous = row.heading firstTime = False else: row.angle = row.heading - previous rows.updateRow(row) previous = row.heading del row, rows
The error I get is:
Runtime error <type 'exceptions.TypeError'>: unsupported operand type(s) for -: 'int' and 'NoneType'
From what I understand because I have no return function after I define my variable previous, it gets erased and the variable is read as NoneType. However with multiple tries I've figured out that the return command only works in def function() codeblocks.
Is there an equivalent to return for updateCursor?
UPDATE: this similar Codeblock produces the same results.
import arcpy fc = r'...' rows = arcpy.UpdateCursor(fc) count = 0 for row in rows: if count != 0: count = count + 1 row.angle = row.heading - previous rows.updateRow(row) previous = row.heading else: count = 1 previous = row.heading del row, rows