Field for Label Expression  - no recognized??

3871
2
Jump to solution
01-27-2015 12:19 PM
MikeBly
Occasional Contributor

HI All,

 

I have a small label expression code written with the help of folks on here - it has been working great for the last couple of years. Simply, it splits the string and abbreviates the text (names).

 

Issue with it is this:

 

I have a polygon FC that I label with landowner names - when I label the FC by simply selecting the field name ([NANAME]) to be the label field, the labels appear as expected, basic labeling 101. When I use this same field in an expression using python as my parser it will no longer work.

 

There is a second field in the table that also contains owner names ([OWNER_NAME]). In the expression, if I replace NANAME with OWNER_NAME the expression will be successful, otherwise it fails. Both fields are STRING.  As mentioned if I remove [NANAME] or just put [OWNER_NAME] before [NANAME] it will run but does not produce the desired results.

 

The only difference from when this was working successfully and now is that I believe I was running ArcGIS 10.0 and now running 10.1.

 

def FindLabel ([NANAME], [OWNER_NAME] ):      text = [NANAME]      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 

 

Thanks for your ideas:

 

Mike

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

Line 8 refers to this line

          S2 = S2[0] + '\n' + S2[1]

Just before that you check the length of list S. Maybe you should also check the length of list S2. If it is 1, "S2[1]"  will generate the error.

if NANAME does not have a space and after the split results in a list with 1 item, it will generate the error.

View solution in original post

0 Kudos
2 Replies
MikeBly
Occasional Contributor

Forgot to mention - the error I receive:

"File "<string>", line 8, in FindLabel

IndexError:list index out of range"

Thanks,

mike

0 Kudos
XanderBakker
Esri Esteemed Contributor

Line 8 refers to this line

          S2 = S2[0] + '\n' + S2[1]

Just before that you check the length of list S. Maybe you should also check the length of list S2. If it is 1, "S2[1]"  will generate the error.

if NANAME does not have a space and after the split results in a list with 1 item, it will generate the error.

0 Kudos