TAGS :Viewed: 14 - Published at: a few seconds ago

[ Python indent error AFTER statement ]

I keep getting an unexpected indent error in Python IDLE, but oddly, to me, it's AFTER the statement. I checked it in Notepad++, and tried deleting spaces and then manually adding 4 in, i.e. not a tab. Below is the code; the error is highlighted after field_value statement. Any suggestions would be much appreciated

i

import arcpy, sys

arcpy.env.workspace = "C:\\"
shapefile = "USCancer2000.shp"
field_name = "friday"

#Add the field
arcpy.AddField_management(shapefile,field_name,"LONG", "","","","","NULLABLE","NON_REQUIRED","")

cursor = arcpy.UpdateCursor(shapefile)

for row in cursor:
    #Get the value of each of our fields, and put them into variables
    c1 = row.getValue("Cnt1")
    c2 = row.getValue("Cnt2")
    c3 = row.getValue("Cnt3")
    p1 = row.getValue("Pop1")
    p2 = row.getValue("Pop2")
    p3 = row.getValue("Pop3")

    #check for missing values, assuming that non-missing values are all greater than or equal to zero
    try: 
        if((min(c1,c2,c3,p1,p2,p3) < 0) or ((p1+p2+p3) == 0) ):  t
            field_value = 0
        else:
            field_value= 1.0

the error is after the field_value= 1.0

Answer 1


It should be

else:
    field_value = 1.0 * (c1+c2+c3)/(p1+p2+p3)
print "done"