-1

I want to develop a model using python.When i want to calculate negative numbers using the model,my script get zero number. Whats wrong in my script ? How can i solve the problem ?

import arcpy
from arcpy import env
env.overwriteOutput = True
env.workspace= r"D:\ppa_test\test.dbf"
arcpy.AddField_management(r"D:\ppa_test\test.dbf",'cf',"Float")
updatecursor = arcpy.UpdateCursor(r"D:\ppa_test\test.dbf",["ppa","pps",'cf'])

for update in updatecursor:
    if update.ppa < update.pps:
        update.cf = (update.ppa - update.pps) / (update.ppa * (1-update.pps))
    elif update.ppa>update.pps:
        update.cf = (update.ppa- update.pps) / (update.pps * (1-update.ppa))
        updatecursor.updateRow(update)
del update
del updatecursor

enter image description here

1 Answer 1

3

your updatecursor.updateRow(update) is not well indented, so you only update your row after the elif statement. It should be at the same level as the if and the elif

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.