-1

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

Thanks for advance

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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