I am writing a Python script using ArcPy and the Field Calculator function (code snippet below) and getting the following error message:

ERROR 000989: Python syntax error: Parsing error SyntaxError: invalid syntax (line 1)

Is line 1 the first line of the code block or the line calling the code block?

netYield = """netYield(ISlimit,multiplier,PASSA,compZone):
x = ISlimit / multiplier
if PASSA == 0:
    if compZone == "Office/Commercial":
        if x < 16000:
            return x
            return 16000
    elif compZone == "Industrial":
        if x < 111000:
            return x
            return 111000
        return x
    return x"""

calcField(HDC,"NetYieldSQFT","netYield(!IS_limit!,!multiplier!,!PA_SSA!,!Comp_Zone!)", "PYTHON",netYield)
  • 2
    Change calcField to arcpy.CalculateField_management and add def at the beginning: netYield = """def netYiel...
    – Bera
    Commented May 1, 2019 at 15:46
  • 1
    @BERA This missing def and different function name are definitely causing error, feel free to add as full answer. I had already started one based on the counting question so incorporated your comment in my edit.
    – SMiller
    Commented May 1, 2019 at 15:57

1 Answer 1


For error purposes, count from the first line of the script that you are trying to run, or a snippet if for example you've copied only part of it into the console.

As BERA commented, the arcpy function is arcpy.CalculateField_management, not calcField (although I'd expect you'd get a different error, such as NameError: name 'calfField' is not defined)

It's possible it's not parsing the codeblock properly due to lack of visible indentation but again I'd expect a different error. Just in case though, follow the example here: https://pro.arcgis.com/en/pro-app/tool-reference/data-management/calculate-field.htm

EDIT: function definitions need to start with def -- add that in your code block (credit for catching this error: BERA).

  • Thanks for the input. This is a piece of a much larger code and calcField is previously defined as the proper function, so that isn't the issue. The issue was definitely the lack of "def" (I completely missed that I skipped this for this codeblock - its 1 of about 10 in this script). The larger problem about the counting is that the codeblock starts on line 75 of my code. the "Line 1" does seem to be referring to line 1 of the codeblock (script line 75).
    – JMVDA
    Commented May 1, 2019 at 17:34
  • 1
    It's important, when posting a question, to format a singleton implementation, which does only what you're asking about. If the standalone works, then you know where to start looking.
    – Vince
    Commented May 1, 2019 at 20:59
  • @Vince - what is a "singleton implementation"?
    – JMVDA
    Commented May 17, 2019 at 19:10
  • 1
    If you paste a fragment of your application in the code window, but it's dependent on objects not present in the window, then no one can use your code to make a working solution. If you strip the code to make a standalone example that works in context for the question, and it works, then you know that the error is elsewhere.
    – Vince
    Commented May 17, 2019 at 19:17

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.