1

I have a repetitive task here at work. It requires that I make multiple fields NULL as I update the geodatabase. Is there a script I can write that I can input the fields and the feature class. Then make all those fields NULL. This script must not make everything NULL in the feature class, only the fields designated. import arcpy

fc = "N:\Updates\CarsonCityNV\CarsonCityNV.gdb\J_POC_S_Studies_Ln"

with arcpy.da.UpdateCursor(fc, ("C1_GAGE", "C2_DISCH", "C3_MODEL", "C4_FCSTR", "C5_CHANN", "C6_HSTR, "C7_SCOUR", "S1_REGEQ", "S2_REPLO",     "S3_IMPAR", "S4_HSTR", "S5_CHIMP", "S6_TOPO", "S7_VEGLU", "S9_HWMS", "S10_REGEQ", "CE_TOTAL", "SE_TOTAL", "A1_TOPO", "A2_HYDRO", "A3_IMPAR", "A4_TECH", "A5_FOAPASS")) as cursor:
 for row in cursor:
    row[0] = None
    row[1] = None
    row[2] = None
    row[3] = None
    row[4] = None
    row[5] = None
    row[6] = None
    row[7] = None
    row[8] = None
    row[9] = None
    row[10] = None
    row[11] = None
    row[12] = None
    row[13] = None
    row[14] = None
    row[15] = None
    row[16] = None
    row[17] = None
    row[18] = None
    row[19] = None
    row[20] = None
    row[21] = None
    row[22] = None
    cursor.updateRow(row)

I'm getting a parsing error on line 5.

3

Just change the path of fc to your feature class, and change YourField to the field name.

import arcpy

fc = "C:\\Temp\\Data.gdb\\FeatureClass"

with arcpy.da.UpdateCursor(fc, ("YourField")) as cursor:
    for row in cursor:
        row[0] = None
        cursor.updateRow(row)

To do multiple fields, just add another field to the tuple and set the row equal to None:

import arcpy

fc = "C:\\Temp\\Data.gdb\\FeatureClass"

with arcpy.da.UpdateCursor(fc, ("YourField", "YourField2")) as cursor:
    for row in cursor:
        row[0] = None
        row[1] = None
        cursor.updateRow(row)
  • You are awesome man, just saved me loads of time. I will try it out. Can I also use this to populate fields with something other than null? – Christopher Harrod Aug 24 '15 at 20:42
  • @ChristopherHarrod yeah, instead of setting the row equal to None, just set it to whatever value you want that fits the field type. If it's a text field, you need to enclose the text in quotes, such as row[0] = "This is my text" – ianbroad Aug 24 '15 at 20:43
  • If I have a thousand rows, will I have to declare each one? i.e. row [0] row [1] row [2]... and so on. – Christopher Harrod Aug 24 '15 at 20:47
  • No, row[0] is actually identifying a field in the tuple. In the example above, row[0] is "YourField", and row[1] is "YourField2". So, it is populating None for every row in each field that you designate - this might explain it better: gis.stackexchange.com/questions/158958/… – ianbroad Aug 24 '15 at 20:49
  • Ok, great, I will give it a go. – Christopher Harrod Aug 24 '15 at 20:54

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.