1

In ArcGIS 10.5, I am building a model that should convert a field of coded values to another code. This seems like it should be a simple if/then statement but I am not getting it. To simplify the process, I populated the target field with the source field's values and then intend on using python to transpose the values. It should be considered a string, but the values are numerical. The field I am trying to edit is "TP_Condi"

In the "Calculate Field" code block:

def reclass:  
if TP_Condi = 3:    
     return 1    
elif TP_Condi = 2:     
     return 8  
elif TP_Condi = 1:    
     return 3  
else:    
     return "error" 

This is the code I was seeking:

enter image description here

5
  • 1
    You need double == when you evaluate a condition, for example if TP_Condi == 3. Take a look at the examples here: desktop.arcgis.com/en/arcmap/10.3/manage-data/tables/… Commented Feb 22, 2018 at 14:27
  • 1
    You also need to indent everything under reclass by 4 spaces Commented Feb 22, 2018 at 14:31
  • I'd suggest spending a few hours on a quick online Python primer, your code has at least 4 different problems that I can see. The difference between = and == in particular is covered very early in just about every Python course I've seen. Commented Feb 22, 2018 at 14:51
  • I've spent days...it is not coming very easy to me Commented Feb 22, 2018 at 14:54
  • What is the field type of TP_Condi? Commented Feb 22, 2018 at 15:03

1 Answer 1

4

As per comments above, you need to use double equals signs and indent the lines within your function definition.

def reclass(TP_Condi):  
  if TP_Condi == 3:    
     return 1    
  elif TP_Condi == 2:     
     return 8  
  elif TP_Condi == 1:    
     return 3  
  else:    
     return 0
1
  • 2
    @cpbride please accept this answer if it solved your issue Commented Feb 22, 2018 at 19:10

Your Answer

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.