1

I am using ArcMap.

In the labels I want to alter the text that is displayed, I do not want to change the data in the attribute table.

In the label expression I add the following after checking the advanced checkbox:

def FindLabel ([sur_notes]):
  return [sur_notes].replace('a string', 'another string')‍‍

The idea is to replace part of a string in the label from the sur_notes text field, however the above throws a syntax error.

I have checked the parser, it is set to python. The string is stored as text.

3
  • 1
    Did you check the Advanced checkbox?
    – Berend
    Jan 6, 2022 at 10:42
  • yes, this is in the advanced area Jan 6, 2022 at 10:42
  • I suspect you have null data in your sur_notes field. So replace won't work. You need to put a check for null in your code and deal with that.
    – Hornbydd
    Jan 6, 2022 at 14:37

1 Answer 1

2

When I copied your expression to ArcMap, I got the same error message, which in this case seemed to be caused by two invisible trailing characters after the closing ).

I solved it by placing the cursor there, and pressing backspace until ) was gone. Then I added ) again.

For those who are interested, the characters appeared to be Zero-width joiners. Pasting the snippet from the question in Notepad++, and then opening the file in a hex editor will reveal: E2 80 8D (which is the character's code point, U+200D) twice.

2
  • Thanks, I have typed out the whole text to avoid such an issue, I still get the error stating Error 0 on line 0 saying Attribute Error: NoneType object has no attribute replace Therefore the issue seems to be the parser not recognising the replace() function. Jan 6, 2022 at 12:55
  • @SpatialDigger I tried that too, and it worked. Other than the trailing characters, your code should work just fine.
    – Berend
    Jan 6, 2022 at 14:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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