This should've been an easy thing, but it gives me problems. I am trying to build a model and I want to use the Field Calculator to replace all the null vaules with a text. I'll do a series of append, and after each append I want to calculate the null values to be a certain text value (which I input). Here is the code that I am using:
def RemoveNULL(Name):
if Name is None:
then return 'Basin'
else:
return Name
I am not very good at writing codes so I am not sure what is wrong here. When I run it, I get this:
Expected 'Then' Failed to execute (Calculate Field).
Any help would be appreciated. Thanks.
Solved! Go to Solution.
we will get this right after all..if you are using the Python parser, and ...if your field is called Name, then the field name in the lower section must be enclosed in exclamation marks
!Name!
Your last two lines are indented improperly, they should be
if Name is None:
return 'Basin'
else:
return Name
Thank you, I tried it, but I still get the same message " Expected 'Then' Failed to execute (Calculate Field)."
your first return statement has 2 spaces, your last one has only 1...spacing must be consistent
Also change your parser from VB to Python (at the top of the field calculator window)
we will get this right after all..if you are using the Python parser, and ...if your field is called Name, then the field name in the lower section must be enclosed in exclamation marks
!Name!
It worked! Thank you!!!!!!! I guess it's time for me to start learning Python:)