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?


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



2 Answers 2


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
        return 1


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.

  • 2
    +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, 2015 at 1:44
  • 1
    @Adam, true true!
    – Paul
    Oct 29, 2015 at 2:29
  • 1
    Thank you for the answers, they are both useful. As a beginning python user, this blog is extremely helpful. Oct 29, 2015 at 17:05

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.