Phyton statement if/else - string/double

4026
9
Jump to solution
12-13-2015 12:31 AM
BartoszBrzeziński1
New Contributor III

Hi,

I stuck with simple expression in field calculator in ArcGis. I hope you`ll help me. The picture below contain two fields "Zal" (Double) and "W_zal" (string). I would like to fill field "W_zal" based on "Zal". For example: if Zal > 10, W_zal is 'text', if Zal < 10 , W_zal is "text_2". I`dont know whats is wrong, brackets, spacing... I`ll be grateful for yours help.

Phyton.jpg

0 Kudos
1 Solution

Accepted Solutions
BartoszBrzeziński1
New Contributor III
0 Kudos
9 Replies
DanPatterson_Retired
MVP Emeritus

select the python parser

and use this as the expression in the code block.  I have written the example verbosely so you can follow the logic.  It is always best to assign the required output and return the final value after the fact to ensure that all is correct.

def convert(val,fld):
    if fld > 10:
        val = "text"
    else:
        val = "text2"
    return val

and this in the expression box

convert(2, !Zval!)

here is an example using a slightly different example... but the principle is the same.

Field_calc_demo_01.png

BartoszBrzeziński1
New Contributor III

Thank you Dan!

0 Kudos
JoeBorgione
MVP Emeritus

Perhaps you could mark this as Answered since the information Dan provides is spot on.

That should just about do it....
DanPatterson_Retired
MVP Emeritus

Joe... I think Bartosz is long gone... it get randomly bumped up the pile over time though

0 Kudos
DanPatterson_Retired
MVP Emeritus

Ahhh good... at least the thread is closed 

0 Kudos
NeilAyres
MVP Alum

But awarding the answer to yourself is a bit....

0 Kudos
DanPatterson_Retired
MVP Emeritus

I didn't... Bartosz thought his thank you was the correct answer... perhaps the final closure is solution enough

0 Kudos
BartoszBrzeziński1
New Contributor III

Hi guys,

Sorry for that mistake.

0 Kudos
DanPatterson_Retired
MVP Emeritus

  Its ok... the question has been getting bumped up randomly over time.  At least it is closed now.

0 Kudos