0

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

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 3, 2014 at 17:03

1 Answer 1

5

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:
 else:
 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.

http://www.pasteur.fr/formation/infobio/python/ch02s03.html

answered Apr 3, 2014 at 17:19
5
  • 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? Commented 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. Commented 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. Commented 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!) Commented 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. Commented Apr 3, 2014 at 20:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.