In the context of this question

Label specific lines in attribute table with syntax- ArcGIS?

i build this python phrase in ArcGIS 10.3:

def FindLabel ([OBJECTID]):
    if long([OBJECTID])==125 and long([OBJECTID]) ==190:
        label = [SHEM_KID] 
        label = None
    return  label

in order to label only OBJECTID number 125 and 190. My problem is that nothing happen, and all label disappear from the map. I try also to remove "long" from the code and it also didn't worked.

Is it possible to do it with python code?

I tried this code also but with no success:

def FindLabel ([OBJECTID], [SHEM_KID]):
    if ([OBJECTID])=='125' AND ([OBJECTID]) =='190':
        label = [SHEM_KID] 
    return  label
  • Checked has to be in list of arguments. Or is correct. See my note to below answer
    – FelixIP
    Nov 27, 2016 at 18:57

1 Answer 1


After @FelixIP's comment, I decided to elaborate more on my answer.

Firstly, you should introduce [SHEM_KID] as an argument to your def, i.e., def FindLabel ([OBJECTID],[SHEM_KID]), otherwise it cannot know what to print as label.

Diagnostic of the query

The first thing you can do is to try running your query on the table, such as OBJECTID = 125 AND OBJECTID = 190, to see if it returns any result. If not, you may be trying to use composite condition on a unique id field. If so, you may be required to format your label expression as string.

Possible workarounds

As @FelixIP advised the labels are treated as strings (even though the field type is not) and your if statement should be if ([OBJECTID])== '125' and ([OBJECTID]) =='190':.

If you are trying to label your features based on a possible unique ID field (OBJECTID) which cannot have two different values therefore does not return anything from a composite conditional (i.e., AND). OBJECTID could either be 125 or 190 not both. Try changing and to or to see if this is what you are looking.

  • Apart from this, it is worth to note that all values receded by find label are treated as strings. This ! Objectid! ==125 is going to be false always
    – FelixIP
    Nov 27, 2016 at 18:55
  • I applied fatih_dur the answer, but I got an error
    – newGIS
    Nov 28, 2016 at 8:37
  • I applied fatih_dur the answer, but I get an syntax error
    – newGIS
    Nov 28, 2016 at 9:10
  • @newGIS, could you specify a bit more what you receive?
    – fatih_dur
    Nov 28, 2016 at 11:33
  • 1
    @newGIS, sorry, I just copied from your second line of code and did not pay attention to python syntax. Now it is fixed.
    – fatih_dur
    Nov 28, 2016 at 23:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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