I am using ArcMap 10.1. I want to use the Calculate Field tool in ModelBuilder on a table where, if field1 is null, it should take the value of field2. If field1 has a value then it should stay as is.
The Update Cursors in arcpy both (da.UpdateCursor10.1, UpdateCursor10.1) have a spot for a SQL clause ("fieldX IS NULL" or "fieldX == """) to limit the extent of records updated.
If there are other updates to be done, the records can be tested to check if they are null (if x is None:)
import arcpy fc = "\\...\\X.gdb\\your_feature_class" fields = ["field1", "field2"] #field1 is row; field2 is row #example 1 with sql rows = arcpy.da.SearchCursor(fc, fields, "", "", "field1 IS NULL") # clause may be "field1 = """ if it's a blank text field for row in rows: row = row rows.updateRow(row) del rows #example 2 without sql clause rows = arcpy.da.SearchCursor(fc, fields) for row in rows: if row is None: # if row == "" row = row rows.updateRow(row) del rows