AddField/Calculate Field Errors in Loop

2074
1
09-02-2011 10:14 AM
MikeMacRae
Occasional Contributor III
Hey everyone,

I am trying to test for a field called "SITE" in any annotation feature classes within a workspace (File gdb) I've been running a few scripts, but I keep getting hung up on the same error message:


ERROR 999999: Error executing function.
Expected end of statement
Failed to execute (CalculateField).


I have a feeling the addfield and calculate field do not like each other in the "else" portion of my loop. I've tried different loop types, but the same error keeps coming up. I did a quick model with these 2 tool and then exported to a python script and they seem to have worked there. Any suggestions?

Thanks,
Mike

import arcpy

from arcpy import env

env.workspace = r"Z:\ESRI\Figure_Sourcing\Figures\Geodatabase\D09_IF_PDA_CR.gdb"

SITE = "D09 Infill"

fcListAnno = arcpy.ListFeatureClasses("*", "Annotation")


for fcAnno in fcListAnno:
    print fcAnno
    fieldListAnno = arcpy.ListFields(fcAnno, "SITE")
    print fieldListAnno

    if not arcpy.Exists(fieldListAnno):
        print "Does not exists"
        arcpy.AddField_management(fcAnno, "SITE", "TEXT", "", "", 50)
        arcpy.CalculateField_management(fcAnno, "SITE", SITE, "VB", "")
    else:
        print "Exists"
        arcpy.CalculateField_management(fcAnno, "SITE", SITE, "VB", "")
Tags (2)
0 Kudos
1 Reply
MikeMacRae
Occasional Contributor III
I solved this.

I had to wrap my SITE variable string in single quotes:

SITE = '"D09 Infill"'


Cheers,
Mike
0 Kudos