Hello,
I am adding something to a script I wrote a few years ago, and in the process, I happened to notice some logic in the script that I would think is wrong, yet it works as desired. This is breaking my brain! While it is apparently not an actual problem, I would love some help in understanding it. (I can't recall why I wrote it this way a few years ago, so my memory is no help here.)
This part of the script uses an arcpy update cursor to populate certain fields in a feature class, depending on what the existing values are. If the State field is Null OR an empty string, it is supposed to be populated with "CA". In other words, all records should have "CA" in this State field. The script is supposed to ONLY edit records that really need editing, which is why I'm using criteria to pick which records get edited, rather than just doing a field calculation on the entire feature class.
However, the code is saying "if it is Null AND it is NOT an empty string, then make it CA." I don't get it. I would think that only Nulls would be picked... or maybe nothing at all.
But the script does correctly populate the field with "CA" if there was an empty string there. I don't understand how this is possible. Any thoughts???
Here is the code:
# If State is blank or null, make it "CA"
if row[field_index_dict.get("State")] is None and row[field_index_dict.get("State")] != '':
row[field_index_dict.get("State")] = "CA"
field_uc.updateRow(row)Thank you for reading!