# Arcmap field calculator python script returns no data

I am running ArcMap 10.2 I have 4 fields with which I am working. many have duplicate entries. in order to find the single correct entry from all the duplicates I am trying to calculate out the erroneous ones. My script runs, but I get no data returned to the GeoloCode field. Why?

codeblock:

``````def cal(GeoloCode):
if ((House_Num >= FROM_ADDR) and (House_Num <= TO_ADDR)) :
return 88
else:
return 1
``````

Expression

``````cal(!GeolocCode!)
``````

you need to pass the fields you're using in your codeblock as arguments to the function, rather than the field that you're calculating. So your code might look something like this:

``````def cal(House_Num, FROM_ADDR, TO_ADDR):
if ((House_Num >= FROM_ADDR) and (House_Num <= TO_ADDR)) :
return 88
else:
return 1
``````

Expression:

``````cal(!House_Num!, !FROM_ADDR!, !TO_ADDR!)
``````

If you don't want to use the codeblock, you can actually accomplish the whole thing inside the expression block with a conditional expression and the fact that

`x >= y and x <= z` is equivalent to `y <= x <= z`.

``````88 if !FROM_ADDR! <= !House_Num! <= !TO_ADDR! else 1
``````

Some people don't like ternaries in python, so if it doesn't make sense to you at first glance, join the club! I like to use it in `Calculate Field` since you don't have to worry with the code block.

• +1 because I like your solution to the calculation Paul, but this doesn't really answer the question of why his code didn't work :) – Adam Oct 29 '15 at 1:44
• @Adam, true true! – Paul Oct 29 '15 at 2:29
• Thank you for the answers, they are both useful. As a beginning python user, this blog is extremely helpful. – James Lambert Oct 29 '15 at 17:05