In ArcGIS 10.3 for Desktop, I work with this point layer and I want to remove all the Sg & Sgs labels from it:

Example 1

So I can get this result only:

Example 2

All the labels are in one field named "field_name" (it is a string type field). I can seperate the data into two fields or export the features with the numbers only.

I prefer to remove it with SQL Expression. I tried this one:

def FindLabel ([field_name]):
  if "Sg" IN [field_name] :
  return [field_name] 

I am getting this error:

Error 0 no line 0.
SyntaxError: invalid syntax (<string>, line 2)   
  • 1
    This is Python not SQL
    – PolyGeo
    Oct 30, 2016 at 19:18

2 Answers 2


Your second line includes the word IN in uppercase and in python it should be lower case in.

Your return line should be inside an else

Possibly better than an in you should just check for the first two characters:

def FindLabel ([field_name]):
    if [field_name][:2] == "Sg" :
        return [field_name] 
  • Midavalo, thanks!!. but i don't understand what the use of the [:2]?
    – newGIS
    Oct 31, 2016 at 6:54
  • @newGIS It looks at the string value and takes the characters up to the third (in python counting starts at 0). So [:2] leaves "Sg" which are characters 0 and 1, stopping at the third character.
    – Midavalo
    Oct 31, 2016 at 8:13

If you only want to label the feature with it Object ID (the numbers you posted in the second picture), then you need to open the layer properties, navigate to the display tab and select label all features the same way and use the field Object ID form the drop down. Simple as that.

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.