Expression: Answer(!Contig_ID!) Code Block: def Answer(CI): if CI ==None: return "N" else: return "Y"
Expression: Answer(!Contig_ID!) Code Block: def Answer(CI): if CI == 99999: # or '99999' if string... return "N" else: return "Y"
expr = '"REFERENCE_FIELD" IS NULL' arcpy.MakeFeatureLayer_management('FEATURE_CLASS_NAME', 'temp', expr) arcpy.CalculateField_management('temp', 'CALCULATED_FIELD', VALUE)
Expression: TestForNullOrEmpty(str(!FieldA!)) Code Block: def TestForNullOrEmpty(fieldVal): if len(fieldVal.strip()) == 0: return "FieldValueWasNullOrEmpty" else: return "FieldHadSomethingInItAlready"
All this solutions will work if you are on a edit session. You must Start editing the feature for the code to replace the value.
try
if not CI:
I was testing for None for Null field -- i.e. if CI == 'None' for field returned with UpdateCursor
Even though a print statement returned 'None', couldn't be tested for as above.
if not ___
seems to work fine.
Cheers
When cursors encounter NULL they return None
and not 'None'
, which is a very important distinction. The former is the Python None object while the latter is simply a string with the word None. The expression CI == 'None'
will never evaluate true for cursors returning fields with NULL. The proper way to check for a NULL field with cursors is CI is None