The screenshot shows a calculate field tool in modelbuilder. The error I'm getting is invalid syntax line 1. I can't see any issues w/the syntax so I'm hoping someone out there can help. It calculates field A to equal field B if field A is not equal to field B.enter image description here

1 Answer 1


Your variable names cannot have a dot (.) in it. Simply change your function to the following:

def update(field1, field2):
   if field1 != field2:
      return field2:
      return field1

Python has some conventions for variable names. You can use any letter, the special characters “_” and every number provided you do not start with it. White spaces and signs with special meanings in Python, as “+” and “-” are not allowed.


  • ustroetz, thank you for the response. The calculate field is being done on a joined table where the two joined tables have the same field name(PIPEID). So I'm calculating table1.PIPEID from table2.PIPEID. Without the period, how can I differentiate the two fields?
    – Steve
    Apr 3, 2014 at 17:38
  • 1
    I am not 100% sure about that and I can't test it (no access to ESRI), but I think you can just leave your expression the way you had it. Only change the Code Block part. Let me know how it goes.
    – ustroetz
    Apr 3, 2014 at 17:43
  • 1
    Right, you can name the variables whatever you want within the codeblock function definition, and pass the correct field names to the function in the calculation expression.
    – nmpeterson
    Apr 3, 2014 at 17:45
  • 1
    @Steve !WATER.C_WATR_PIPE.PIPEID! gets passed to field1 and !Water_Pipe.PIPEID! gets passed to field2, you still use the update(!WATER.C_WATR_PIPE.PIPEID!, !Water_Pipe.PIPEID!)
    – ianbroad
    Apr 3, 2014 at 19:51
  • Thanks for the help! I'm completely green to codeblocks and variables so it took me a little while to figure how to pass along variables in the codeblock. Didn't realize all I had to do was copy/paste ustroetz's response :) Have it working now. Thanks again for the help.
    – Steve
    Apr 3, 2014 at 20:32

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.