3

I am trying to use a find label expression that changes the font of one field, [NUMBERNAME]. I am using the Python parser of ArcGIS 10.3.1 for Desktop.

All fields have a data type of text. This is what I have...

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

I am getting an error. Any thoughts as to what is wrong?

Error:

The expression contains an error. Modify the expression and try again. Error 0 on line 0. SyntaxError: invalid syntax(string, line 2).

enter image description here

Midavalo
30k11 gold badges53 silver badges108 bronze badges
asked Jul 10, 2015 at 18:25
2
  • Paste here this error. Commented Jul 10, 2015 at 18:29
  • You might find it simpler to use .format() : "{0}\n{1}\nBLK:{2}\nSEC:{3}".format(absName, [BLOCK], [SURNUM]) Commented Jul 13, 2015 at 18:15

2 Answers 2

8

You currently have:

lineone = "A:" + [NUMBER] but [NUMBER] isn't defined anywhere.

Any fields that you want to use in the expression, you need to include as a parameter to the function.

So, it looks like you would want:

def FindLabel ([NUMBERNAME], [NUMBER], [BLOCK], [SURNUM]):
 ...
answered Jul 10, 2015 at 18:49
3

You need to allow for [NUMBER], [BLOCK], and [SURNUM] in your function.

def FindLabel([NUMBERNAME],[NUMBER],[BLOCK],[SURNUM]):

And make sure to account for None to be returned if any of those fields could be empty.

answered Jul 10, 2015 at 18:53

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.