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:
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.
-
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– Steve2014年04月03日 17:38:00 +00:00Commented Apr 3, 2014 at 17:38
-
1I 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– ustroetz2014年04月03日 17:43:41 +00:00Commented Apr 3, 2014 at 17:43
-
1Right, 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– nmpeterson2014年04月03日 17:45:45 +00:00Commented 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– ianbroad2014年04月03日 19:51:29 +00:00Commented 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– Steve2014年04月03日 20:32:37 +00:00Commented Apr 3, 2014 at 20:32
Explore related questions
See similar questions with these tags.