graeme

Label Expression Example using Python will not give "expected" result

Discussion created by graeme on Jun 20, 2012
The code below is given as an Example of the new Python parser for Label Expression in its documentation.

However, it looks like, and I think I've read somewhere, that all values get passed into the FindLabel expression as strings because when you run it against World Cities they all draw in large red letters.

def FindLabel ( [NAME], [POPULATION] ):
    if [POPULATION] >= 250000:
        return "<CLR red='255'><FNT size = '14'>" + [NAME] + "</FNT></CLR>"
    else:
        return [NAME]


Change the expression to the following (i.e. cast the POPULATION field as int) and you then get the expected result.

def FindLabel ( [NAME], [POPULATION] ):
    if int([POPULATION]) >= 250000:
        return "<CLR red='255'><FNT size = '14'>" + [NAME] + "</FNT></CLR>"
    else:
        return [NAME]


Can the code examples, particularly any that involve number comparisons or manipulations, be reviewed, please?

Outcomes