Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Conditional Labelling - Python

$
0
0
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:

SMITH,
J.J.

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:

Code:

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]
    else:
          S2 = S[0] + ',\n'
          ABBREV = ''
          S3 = S[1].split(' ')
          for each in S3:
              if not each in ('&', 'AND'):
                    ABBREV = ABBREV + each[0:1] + '. '
              else:
                    ABBREV = ABBREV + each[0:1] + ' '
          S2 = S2 + ABBREV[0:-1]

    return S2

Any thoughts on this are much appreciated.

Regards,

Mike

Viewing all articles
Browse latest Browse all 2485

Trending Articles