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.
-
1Did you check the Advanced checkbox?Berend– Berend2022年01月06日 10:42:17 +00:00Commented Jan 6, 2022 at 10:42
-
yes, this is in the advanced areaSpatial Digger– Spatial Digger2022年01月06日 10:42:54 +00:00Commented 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– Hornbydd2022年01月06日 14:37:08 +00:00Commented Jan 6, 2022 at 14:37
1 Answer 1
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.
-
Thanks, I have typed out the whole text to avoid such an issue, I still get the error stating
Error 0 on line 0
sayingAttribute Error: NoneType object has no attribute replace
Therefore the issue seems to be the parser not recognising the replace() function.Spatial Digger– Spatial Digger2022年01月06日 12:55:41 +00:00Commented 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– Berend2022年01月06日 14:04:50 +00:00Commented Jan 6, 2022 at 14:04
Explore related questions
See similar questions with these tags.