AnsweredAssumed Answered

Calculate new field in multiple tables based on an existing field that is not always present

Question asked by Diomedes275 on Jan 30, 2019
Latest reply on Mar 6, 2019 by Diomedes275

I have a set of file geodatabase tables that are an output form another process.  From that output I created a subset based on part of the filename.  I would like to merge all these files together but the merge tool will not work because in some tables a field with the common name "PROJECT" differs in length.  My solution is to add a new field "Project1" and calculate it using the field calculator in arcpy.  Unfortunately the problem I am having with this is that not all of the tables in my subset have the field "PROJECT" so the calculation is giving me the error: ExecuteError: ERROR 000539: Invalid field PROJECT
Failed to execute (CalculateField).

This leads me to believe, that I need to set up some sort of code block with IF ELSE to iterate through this list of tables and ignore tables where the "PROJECT" field is not present and continue.  I need help writing that and figuring out where to place the code block.  Any help is greatly appreciated.  I am using ArcGIS desktop 10.4.1. This is what I have so far, thanks in advance.

import arcpy
import os
from arcpy import env
env.workspace = r"C:\John\test22\Caribou_Plumas_Testing.gdb"
list_NRes_Tables = arcpy.ListTables("*_NRes*")

for myTables in list_NRes_Tables:
    arcpy.AddField_management(myTables,"Project1","TEXT",255,"","","Project1", "NULLABLE", "NON_REQUIRED")
    for myTables in list_NRes_Tables: