I'm trying to write a simple if/else statement where if the value isn't found, Arcmap keeps the current field value. I've tried using the default python command of pass but it still overwrites the values to null. Any advice? Code from codeblock below.
def reclass(mystring):
if (mystring == 'C-4'):
return 'Central Business District'
else:
pass
Scott
Solved! Go to Solution.
The better way is to pass both fields to the function:
def reclass(f1, f2):
if (f1 == 'C-4'):
return 'Central Business District'
else:
return f2
and call it using:
reclass(!field1!, !field2!)
In Python, the default for a function is to return None, which will get converted to NULL in your case. Try:
def reclass(mystring):
if (mystring == 'C-4'):
return 'Central Business District'
else:
return mystring
I'm actually running it against a different field though so I don't want it to just return mystring, I should've stated that.
Here's what I want:
The field being calculated is field2
reclass(!field1!)
def reclass(mystring):
if (mystring == 'C-4'):
return 'Central Business District'
else:
return the existing value in field2 or just do nothing to field2
Does that make sense? Can I just define field2 in the codeblock and say if else return the value for field2?
Scott
The better way is to pass both fields to the function:
def reclass(f1, f2):
if (f1 == 'C-4'):
return 'Central Business District'
else:
return f2
and call it using:
reclass(!field1!, !field2!)
Perfect, this is what I was looking for.
Scott