Conditional Labelling - Python

Discussion created by mbly29 on Feb 6, 2014
Latest reply on Feb 11, 2014 by hua17
HI All,

Last year about this time I posted a thread about conditional labeling using python.  I received awesome assistance and was successful in working out a successful script, which I use regularly.

I need to redo this script to accommodate some changes made to the data and looking for some input. The current script modifies the label for owner names. Example: in the table the value is SMITH, JOHN JASON. The script/expression displays this as:


The value now appears in the table as JOHN JASON;SMITH  with first name first and last name second. I would like the script to label with last name first, followed by initials as shown above.

Here is the current working script:

def FindLabel ([ANAME], [OWNER_NAME] ):
     text = [ANAME]
     text2 = [OWNER_NAME] 
     S2 = text.split(',')
     S = text.split(', ')
     if len(S) == 1:
          S2 = S[0].split(' ', 1)
          S2 = S2[0] + '\n' + S2[1]
          S2 = S[0] + ',\n'
          ABBREV = ''
          S3 = S[1].split(' ')
          for each in S3:
               if not each in ('&', 'AND'):
                    ABBREV = ABBREV + each[0:1] + '. '
                    ABBREV = ABBREV + each[0:1] + ' '
          S2 = S2 + ABBREV[0:-1]

     return S2

Any thoughts on this are much appreciated.