1

I've been unable to solve this seemingly rudimentary issue of running a python snippet via the label expression option in ArcGIS. I've read this documentation Building label expressions, but wasn't able to get too far.

Can you assist me with the correct code to run to achieve labeling only years in the form of 2015, 2016 etc... and not label anything that has a 0?

I've read through and tried numerous iterations of code to run however all came with error except one. My examples and results are as follows:

Here is a screen shot of the attribute table and the current results, I've only achieved.

enter image description here

here is the first code I tried to run

def YearLabel ( [Most_Recen] ): if int([Most_Recen]) = 0: return " " else: return [Most_Recen]

however an error results

enter image description here

3

The single equals sign (=) is used for assigning a value, not testing for equality. To test for equality, use the double equals sign (==).

So instead of:

if int([Most_Recen]) = 0:

it should be:

if int([Most_Recen]) == 0:

Although, since zero (0) evaluates to false, you could skip the equality test altogether, and just check the "truthiness" of the value itself. Therefore you can simplify it with:

if int([Most_Recen]):
    return [Most_Recen]
else:
    return ""

(I would also return an empty string rather than a space.)

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.