[GIS] Check that a Variable is NOT Equal to Multiple Values

arcgis-desktopexpressionlabelingpython-parser

I am trying to use a check a field against several values (eg: [Name] != 'NONE', and [Name] != 'N/A'). This is for the label expression builder within ArcGIS and I am using it eliminate label for fields with NONE, @ or other invalid fields.

I have tried:

def FindLabel ([Name]):
      if [Name] != 'NONE' or [Name] != 'N/A':
         return None
      elif:
         return [Name]

I also tried separating these out:

def FindLabel ([Name]):
     if [Name] != 'NONE':
        return None
     elif [Name] != 'N/A':
        return None
     elif:
        return [Name]

The above results in the labels being printed for the invalid values still despite the if loops.

Is there a way to check a value against a list and eliminate labels, while printing those for valid values?

Best Answer

The code that works for this problem is:

def FindLabel ([Name]):
     if [Name] not in ['NONE','N/A']:
          return [Name]
Related Question