AnsweredAssumed Answered

Help with syntax error in Calculate Field tool

Question asked by Kayden_Sim on Jul 29, 2020
Latest reply on Jul 29, 2020 by sporock

Hi Esri community, I am getting an error for a script I've written to calculate several fields. The error message says there is a syntax error, but I have tried to fix it and I don't know what I've done wrong. The error message is as follows: 

 

Runtime error Traceback (most recent call last): File "<string>", line 97, in <module> File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3457, in CalculateField raise e ExecuteError: ERROR 000989: Python syntax error: Parsing error IndentationError: unexpected indent (line 1) 

 

The script I used worked for every field except for the last one, which was the only field that needed codeblock to calculate. The portion of the script for the last field is as follows (line 97 is the last line) : 

 

# Import system modules #
import arcpy
# Set environment settings #
arcpy.env.workspace = r"D:\mapsfolder"

# Set local variables for unassigned #
inTable = r"D:\mapsfolder\table.shp"
fieldName13 = "unassigned"
expression13 = "unassigned_fxn(!type1year!,!type2year!,!type1end!,!type2end!,!eventyear!,!occurrence!)"
codeblock13 = " " " def unassigned_fxn(inValue1, inValue2, inValue3, inValue4, inValue5, inValue6):
result1 = inValue1
result2 = inValue2
result3 = inValue3
result4 = inValue4
result5 = inValue5
result6 = inValue6
if result1 == 0 and result2 == 0 and result3 == 0 and result4 == 0:
         return result5 * result6
else:
         return 0" " "
# Execute Calculate Field #
arcpy.CalculateField_management(inTable, fieldName13, expression13, "PYTHON_9.3", codeblock13)

 

 

Thanks for any help!! 

Outcomes