Select to view content in your preferred language

Field Calculator - Python - using 3 fields for parameters get syntax error

863
3
11-21-2012 07:43 AM
by Anonymous User
Not applicable
Original User: lbowman

I'm trying to create a model to do field calculations using 3 fields for parameters. I get the attached syntax error when I do. I'm successful in using 2 fields as parameters but when I add the 3rd, I get the error. Is there a limit or am I doing something else wrong?

Other suggestions for doing field calculations which could be easily modified by another.

Attached is the field calculator w/ code and error.

Any help would be very much appreciated. Thank you!
0 Kudos
3 Replies
MathewCoyle
Honored Contributor
Can you copy and paste your code instead of using a screen shot? It is a little difficult to make out.

What are the data types of your three fields? Which field and code did you add that introduced the problem?
0 Kudos
by Anonymous User
Not applicable
Original User: lbowman

Thanks for the quick reply. I thought it was adding the 3rd field but it seems that it is the 3rd field that I've added that's the problem. If I only add this one field which is a text field with coded-value domain, it fails.

Expression:
calcCompliance(!rail_alignment!)

Code Block:
def calcCompliance(align):
      return None

Error:
Executing (Calculate Field): CalculateField "Existing Guide Rails" compliance calcCompliance(!rail_alignment!) PYTHON_9.3 "def calcCompliance(align):\n      return None\n"
Start Time: Wed Nov 21 13:20:35 2012
ERROR 000539: <type 'exceptions.SyntaxError'>: invalid syntax (<expression>, line 1)
Failed to execute (Calculate Field).
Failed at Wed Nov 21 13:20:35 2012 (Elapsed Time: 0.00 seconds)

If I change the field used in the expression it works just fine. The field is a text field, length 25, and does contain double quotes. But one other field I tried has double quotes (but only 1 per record, the field that it fails on has some records with 2 double quotes as such:
6" - 12" Out of Alignment. Would it be failing because of that?

Let me know if you have any suggestions. Thanks!
0 Kudos
LaureBowman
Emerging Contributor
The problem was a field where records had 2 double quotes. Using the following for the Expression:
calcCompliance(!rail_elem_cond!, !rail_ht!, '!rail_alignment!'.replace("\"",""))

solved the problem. I got this from a post on Stack Exchange.

Thanks for trying to help!
0 Kudos