0

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)

My question is: Which line 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
        else:
            return 16000
    elif compZone == "Industrial":
        if x < 111000:
            return x
        else:
            return 111000
    else:
        return x
else:
    return x"""

calcField(HDC,"NetYieldSQFT","netYield(!IS_limit!,!multiplier!,!PA_SSA!,!Comp_Zone!)", "PYTHON",netYield)
  • 1
    Change calcField to arcpy.CalculateField_management and add def at the beginning: netYield = """def netYiel... – BERA May 1 at 15:46
  • @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 May 1 at 15:57
0

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 May 1 at 17:34
  • 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 May 1 at 20:59
  • @Vince - what is a "singleton implementation"? – JMVDA May 17 at 19:10
  • 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 May 17 at 19:17

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.