I have this code which works...

def FindLabel ([NUMBERNAME], [NUMBER], [BLOCK], [SURNUM]):
      lineone = "A:"+ [NUMBER]
      absName = "<CLR red='255'><FNT size = '14'>" + [NUMBERNAME] + "</FNT></CLR>"
      if [NUMBERNAME] is not None:
          return lineone + '\n' + absName + '\n' + "BLK:" + [BLOCK] + '\n' + "SEC:"+ [SURNUM] 

However I have some field values in [NUMBERNAME] that contain the reserved ampersand character (&). If the value contains the ampersand character the label looks like this...

<CLR red='255'><FNT size = '5.5'>T&P RR CO</FNT></CLR>

Versus (in this example) a label that looks like...


I have found this documentation, which references this code to fix the ampersand issue....

 Function FindLabel ([LABELFIELD])
  NewString = Replace([LABELFIELD],"&","&amp;")  
  FindLabel = "<ITA>" & NewString & "</ITA>"
End Function

This is in VBScript. How would I do something similar to this using the Python parser of ArcGIS 10.3 for Desktop?

  • I'm confused because you have referenced documentation for the ArcGIS Pro application on a question that seems to be written for ArcMap.
    – PolyGeo
    Jul 10, 2015 at 23:55
  • @PolyGeo Yes, the documentation referenced is for ArcGIS Pro, and yes I am using ArcGIS Desktop 10.3.1. I listed the documentation since it referenced a VBScript code that works in ArcGIS Destktop 10.3.1, however I am looking for a python parser that has the same functionality as in the VBScript example that they list. I have been pointed in the right direction, and the question was answered.
    – a1234
    Jul 12, 2015 at 14:28

2 Answers 2


Python has a similar replace method you can use:

def FindLabel ([NUMBERNAME], [NUMBER], [BLOCK], [SURNUM]):
      lineone = "A:" + [NUMBER]
      numName = [NUMBERNAME].replace("&", "&amp;")
      absName = "<CLR red='255'><FNT size = '14'>" + numName + "</FNT></CLR>"
      if [NUMBERNAME] is not None:
          return lineone + '\n' + absName + '\n' + "BLK:" + [BLOCK] + '\n' + "SEC:"+ [SURNUM]
  • 1
    Thanks so much! This is exactly what I was looking for, works like a charm!
    – a1234
    Jul 12, 2015 at 14:29


newString = string.replace("&", "&amp;")

Where string is your field with ampersand.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.