2

I am very new to Python and need what I believe is a very basic script in order for my field to represent another fields' input, if the field's value is 0. I tried to search for this, but gave up after two hours... I am currently trying the script on two fields that I made only for this purpose, using ArcGIS 10.0. So what I want to do is returning the value of field "TESTFIELDBEREGNER" in "TESTFIELD" IF TESTFIELD=0, else return TESTFIELD. I believe the error may lie in the definition, as I don't know how to define strings in this correctly? The geoprocessing results window tells me there is a syntax error in line 2.

def RemoveNULLS(x, v):
  if x == '0'
    return v 
  else:
    return x

 RemoveNULLS( !TESTFIELD!, !TESTFIELDBEREGNER!)
3

The code should work, just add the colon after if statement and proper indentation:

def RemoveNULLS(x, v):
    if x == '0':
        return v
    else:
        return x

RemoveNULLS( !TESTFIELD!, !TESTFIELDBEREGNER!)

Be careful with what data type used for the x (if it is an integer, you cannot use '0', should be 0).

0

Note that in your case you could also select by attribute "TESTFIELD"='0' (select by attribute), then update only those values with field calculator. If you have a vera large table and very few cases with "TESTFIELD"='0' , it could be faster.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.