Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to calculate the PIPEID field to equal the G_KEY_COMP field if PIPEID is null or PIPEID and G_KEY_COMP do not match. I think the first condition of the PIPEID being null is covered by the second condition of the fields not matching? I'm a novice on this topic and can't get the syntax I have to work. Here's what I've piecemealed together:

Pre-Logic Script Code:

def update(PIPEID,G_KEY_COMP):
  return G_KEY_COMP
 return PIPEID


I'm posting a screenshot of the field calculator window since I'm not able to get the indentation right in the codeblock.

enter image description here

share|improve this question
if and else need to be indented the same amount, inside the function – Barbarossa Mar 28 '14 at 17:56
also there is a missing : at the end of the if – radouxju Mar 28 '14 at 19:50
up vote 3 down vote accepted

Your code needs to be:

def update(PIPEID,G_KEY_COMP):
  if PIPEID is None:
    # PIPEID is NULL
    return G_KEY_COMP
    # PIPEID has a different value to G_KEY_COMP
    return G_KEY_COMP
    return PIPEID
share|improve this answer
Thanks, I tried this snippet and it gives a syntax error 000989 on line 5. Not sure why as it looks good to me. Also, thank you for including comments :) – Steve Mar 28 '14 at 19:49
again, : is missing after the second if – radouxju Mar 28 '14 at 19:51
Awesome! Thanks for the help guys! – Steve Mar 28 '14 at 19:55

Pythonic inline if is working in Field Calculator expression

res=(on_false, on_true)[condition]

arcpy.CalculateField_management("fc" , "field" ,"(!PIPEID!, !G_KEY_COMP!)[!PIPEID! != !G_KEY_COMP!]" , "PYTHON_9.3")
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.