AnsweredAssumed Answered

Easy points: Explain how I can use square brackets in a label expression.

Question asked by huffmanp on Feb 26, 2014
Latest reply on Feb 26, 2014 by huffmanp
I thought it would be easy to take a test table item with the format DEAN, JOHN, use a python expression split it at the comma and just use the last name for a label. I could condense the steps down to one line in an IDLE window:

>>> name = fullname
>>> print name
DEAN, JOHN
>>> lname = (name.split(',')[0])
>>> print lname
DEAN

But in the ArcDesktop 10.2.1 label expression window I put:
([NAME].split(',') [0])    

which gave me the "No features found. Could not verify expression." message.  Apparently, [0] means go find an item called 0 in the table to ArcDesktop.  I had to check the advanced box and use

def FindLabel ( [NAME] ):
  S = ([NAME].split(',') [0])
  return S

to get the job done.  Is that the only way, or is there some way to call the first element without square brackets in python?

Outcomes