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
1 Answer 1
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– toWGS842014年10月21日 10:19:05 +00:00Commented 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.2014年10月21日 10:26:46 +00:00Commented Oct 21, 2014 at 10:26
-
Tank's. I've removed the exlmation marks, but doesn't work. But the syntax seems correct.toWGS84– toWGS842014年10月21日 10:50:11 +00:00Commented 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?2014年10月21日 10:58:50 +00:00Commented 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.recurvata– recurvata2014年10月21日 12:01:57 +00:00Commented Oct 21, 2014 at 12:01
Explore related questions
See similar questions with these tags.