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
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!)
  • 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! – toWGS84 Oct 21 '14 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. – PolyGeo Oct 21 '14 at 10:26
  • Tank's. I've removed the exlmation marks, but doesn't work. But the syntax seems correct. – toWGS84 Oct 21 '14 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? – PolyGeo Oct 21 '14 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. – recurvata Oct 21 '14 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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