Calculate Field to update a column based on not null in another column

01-21-2019 06:22 PM
New Contributor II

Calculate Fields

(i"m new to arcpy and arcgispro)

I'm attempting to use the Calculate Field to update a column based on non-null values in another column:


Code Block:
def UpdateLoc(nameGaz):
    if (nameGaz != none):
        return 'L'

(I've tried != NULL and IS NOT NULL as well) 

I'm not sure where I am going wrong here, I get '2 parameters are missing or invalid'

Tags (2)
0 Kudos
3 Replies
MVP Esteemed Contributor

For this type of basic conditional check, you don't need a code block.  Set the parser to Python and try the following expression:

'L' if !GAZETTED_LOCALITY_NAME! is not None else None‍‍

NULL in databases and data stores gets mapped to Python None.

MVP Legendary Contributor

and if you want to use your code block, you don't include the …. Expression : nor the Code block lines,

Underneath Type (which is the field you are trying to calculate values for, you put the expression in there




Then in the code block section

Code Block


def UpdateLoc(nameGaz):
    if nameGaz is not None:
        return 'L'‍‍‍
    return None

code blocks and expression lines take a bit of getting used to.

If you reuse and expression a lot, you can save them a *.cal files, and then reload them

New Contributor II

Thanks for that - it wasn't clear what went in what box from the example I ripped off (Calculate Field Python examples—Data Management toolbox | ArcGIS Desktop ).

0 Kudos