3

I need to concatenate the value of two fields excluding empty values, using Field calculator. The fields are: AREA_HI and AREA_LO

I have tried using a Python script but ArcGIS returns an error "000539 : Error message from Python."

def concat_fields(!AREA_HI!, !AREA_LO!):
 if !AREA_HI!.strip() == "" or !AREA_LO!.strip() == "":
 return ""
 else:
 return !AREA_HI! + !AREA_LO!

On the base of suggestions and comments i've tried to modify the code. The result is ever negative.

The last code used, it seems formally correct but show an "indentation error (n. 000539) unexpected indent ( line 1)"...

 def concat_fields(AREA_HI, AREA_LO):
if AREA_HI.strip() == " " or AREA_LO.strip() == " ":
 return ""
else:
 return AREA_HI + AREA_LO
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Oct 21, 2014 at 10:01

1 Answer 1

2

When you define your concat_fields function there should be no exclamation marks used because you are at that stage dealing with Python variable names.

def concat_fields(AREA_HI, AREA_LO):
 if AREA_HI.strip() == "" or AREA_LO.strip() == "":
 return ""
 else:
 return AREA_HI + AREA_LO

However, be sure to leave the exclamation marks on where you call the function as part of the expression because at that point you are recalling field values.

OtherField = concat_ fields(!AREA_HI!, !AREA_LO!)
answered Oct 21, 2014 at 10:09
9
  • Like this? Still does not work. def concat_fields(AREA_HI, AREA_LOW): if !AREA_HI.strip()! == "" or !AREA_LOW.strip()! == "": return "" else: return !AREA_HI! + !AREA_LOW! Commented Oct 21, 2014 at 10:19
  • 1
    @toWGS84 There should be no exclamation marks anywhere in the panel where you define the function - I can still count 8. I'm writing from my iPhone so my formatting and editing options are a bit limited at the moment. Commented Oct 21, 2014 at 10:26
  • Tank's. I've removed the exlmation marks, but doesn't work. But the syntax seems correct. Commented Oct 21, 2014 at 10:50
  • Can you copy/paste your current code from the field calculator into your question and also the exact error message that it produces, please? Commented Oct 21, 2014 at 10:58
  • Are your AREA_HI and AREA_LO fields text fields? Area is typically a numeric format, in which case you'd probably check for None rather than an empty space. Commented Oct 21, 2014 at 12:01

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.