Thursday, 26 March 2015

arcgis desktop - ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 2)


I have a Field Calculator I am using with Python and I keep getting the above error. Below is the screenshot of my Field Calculator I am using.


enter image description here


What am I doing wrong here?



Answer



You are confusing the scope when defining your function and its arguments in the pre-logic script. An actual field cannot be within the definition of the function in the pre-logic script. See screen shot of a working field calculator function:


ArcMap 10.1 Field Calculator with Pre-Logic Script Code, field to the left is the field that is being calculated (it does not have to be highlighted).



Notice how temp is defined as an argument in the pre-logic script code and keeps its name when used inside the function. Then in the JanClass = block I use the function and define which field values I want to use.


So in your case add another argument to your function, call it objectID, and then when you call your function in the box below feed it !OBJECTID!. Additionally I am fairly certain that OBJECTID cannot be used in field calculator operations. If you are trying to do an auto increment function refer to the answer given by adouxju on this question - (How to auto increment a field in a feature class?).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...