Expression: Answer(!Contig_ID!) Code Block: def Answer(CI): if CI ==None: return "N" else: return "Y"
Yes, see 2.3.1 Truth Value Testing . Since there are several other data structures that exhibit falsy behavior, e.g., an empty string, testing for false instead of for None might result in some non-NULL fields getting treated as NULL.
Joshua -- many thanks -- I am a Python newbie -- does the Python None object equate to false in logical tests?
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
None
'None'
CI == 'None'
CI is None
try
if not CI:
I was testing for None for Null field -- i.e. if CI == 'None' for field returned with UpdateCursorEven though a print statement returned 'None', couldn't be tested for as above.
if not ___
seems to work fine.
Cheers
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.
Expression: TestForNullOrEmpty(str(!FieldA!)) Code Block: def TestForNullOrEmpty(fieldVal): if len(fieldVal.strip()) == 0: return "FieldValueWasNullOrEmpty" else: return "FieldHadSomethingInItAlready"
expr = '"REFERENCE_FIELD" IS NULL' arcpy.MakeFeatureLayer_management('FEATURE_CLASS_NAME', 'temp', expr) arcpy.CalculateField_management('temp', 'CALCULATED_FIELD', VALUE)
Expression: Answer(!Contig_ID!) Code Block: def Answer(CI): if CI == 99999: # or '99999' if string... return "N" else: return "Y"
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.