'If/else statement in Python ArcGIS field calculator

I have a county file in arcmap and trying to assign values in field calculator based on county name. I don't have experience writing scripts.

The county field is tl_2010_55_county10.NAMELSAD10, and the new field in which I am trying to assign values is tl_2010_55_tract10.NitValue. The type is "short".

I am in field calculator, and have the Python "code block" up:

def myValue( !tl_2010_55_county10.NAMELSAD10!, !tl_2010_55_tract10.NitValue! ):
  if ( !tl_2010_55_county10.NAMELSAD10! == "Clark County"):
   !tl_2010_55_tract10.NitValue! = 1
  else:
   !tl_2010_55_tract10.NitValue! = 0

Then, in the little box at the bottom that says: !tl_2010_55_tract10.NitValue! =

I call the function:

myValue( !tl_2010_55_county10.NAMELSAD10!, !tl_2010_55_tract10.NitValue! )

However, when I run this, it says there was a failure geo-processing.



Solution 1:[1]

Try this in the big codeblock:

Dim blah
  if !tl_2010_55_county10.NAMELSAD10! = "Clark County" Then
    blah=1
  else blah = 0
  End If

And the just type "blah" (without the quotations) into the lower box after NitValue! =

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Matt Goodman