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.

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 6, 2022 at 10:35
3
  • 1
    Did you check the Advanced checkbox? Commented Jan 6, 2022 at 10:42
  • yes, this is in the advanced area Commented 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. Commented 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.

answered Jan 6, 2022 at 10:50
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. Commented 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. Commented Jan 6, 2022 at 14:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.