ArcGIS Pro 2.9 - Python Script Failing for Labels

2931
18
11-22-2021 08:05 AM
PeteJordan
Occasional Contributor III

Before upgrading to 2.9, I never had an issue with my labeling code at all:

 

def FindLabel([TrailName],[Width]):

  str_list = []
  if [TrailName] not in (None, "<NULL>","<Null>", "", "0"):
    str_list.append([TrailName])
    
  if [Width] not in (None, "<NULL>","<Null>", "", "0", " "):
    width_str = '<ITA>Width = {}\'</ITA>'.format("<ITA>" + [Width] + "</ITA>")
    str_list.append(width_str)    

  label_str = '\n'.join(str_list)
  return(label_str)

 

 

  Now that I switched to 2.9, I'm now getting the following error:

Invalid Expression

Traceback (most recent call last):

   File "<expression", line 1, in <module>

NameError: name 'FindLabel' is not defined

  I have pasted the exact same code into ArcMap 10.8.1 and it works just fine.  So I'm very confused why all of a sudden a labeling script I've used for over a year now just fails in Pro?

  Any ideas?

 

 

 

 

18 Replies
PeteJordan
Occasional Contributor III

@JoeBorgione:  Due to another unrelated bug that prevents me from properly working in 2.9, I actually did just that and uninstalled 2.9 and reinstalled 2.8 and the 3 service packs and now that I'm back in 2.8.3, the code works fine.  So yes, it seems to be yet another bug I've found in 2.9.

  Bad thing is I'm unable to even submit a bug report due to the website having issues for the past few days (I did get ESRI support on the phone and they're looking into the issue now), but it will be another bug I'll have to remember to submit with 2.9 then...

JoeBorgione
MVP Emeritus

Let ESRI log the bug; it's their problem...

That should just about do it....
PeteJordan
Occasional Contributor III

Hopefully they see it then, but at least I know it's a version issue then and one of 2 bug issues that is enough for me not to continue using 2.9...

0 Kudos
JoeBorgione
MVP Emeritus

Hey @KoryKramer ; you might want to read this post....

That should just about do it....
0 Kudos
WendyHarrison
Esri Contributor

Thanks for bringing this to our attention.  We're working on a fix for it.  Until then you can use the workaround below.

swapping the quotes and removing the escape character can be used as a workaround

def FindLabel([TrailName],[Width]):
str_list = []
if [TrailName] not in (None, "<NULL>","<Null>", "", "0"):
str_list.append([TrailName])
if [Width] not in (None, "<NULL>","<Null>", "", "0", " "):
width_str = "<ITA>Width = {}'</ITA>".format("<ITA>" + [Width] + "</ITA>")
str_list.append(width_str)
label_str = '\n'.join(str_list)
return(label_str)

This was the original part that was broken

'<ITA>Width = {}\'</ITA>'

This is the updated part

"<ITA>Width = {}'</ITA>"

 

PeteJordan
Occasional Contributor III

Thanks Wendy for that workaround.  I just feel I have a lot of scripts and taking the time doing this to every one of them might not be worth it.  I think I'll just skip over 2.9 until this (and another bug I have that prevents me from using 2.9) are resolved...

WendyHarrison
Esri Contributor

the number for this issue is BUG-000144967.  You can track it through support services.

WendyHarrison
Esri Contributor

@PeteJordan 
here's the second part you requested


def FindLabel([TrailName],[Width]):

  str_list = []

  if [TrailName] not in (None, "<NULL>","<Null>", "", "0"):

    str_list.append([TrailName])

  if [Width] not in (None, "<NULL>","<Null>", "", "0", " "):

    width_str = "<FNT size = '20'><ITA>Width = {}'</ITA>".format("<ITA>" + [Width] + "</ITA>")+"</FNT>"

    str_list.append(width_str)   

  label_str = '\n'.join(str_list)

  return(label_str)

resulting in a label like this

WendyHarrison_0-1640125258239.png

 

0 Kudos
PeteJordan
Occasional Contributor III

@WendyHarrison:  Yes I figured it out and deleted the message, but guess you must have seen it before I was able to remove the post.  It was the single quote that I had accidentally gotten rid of when I should have kept that one part and only changed the other single quotes was my issue...  

0 Kudos