Calculate Field inside Loop for fcList

المشرف العام

Administrator
طاقم الإدارة
I'm stuck! After a painstaking effort to get here, I'm really stuck on my CalculateField function. I can see the end in sight, but the sticking point is how to correctly type the syntax. So I'm not particularly tied to the variables I assigned up front, but if you think it works better. The issue is syntax for the expression. Help!

####################################################### # MLB Birthdate Script Add/Calculate Field add-on # Import modules import arcpy import os import traceback arcpy.env.overwriteOutput=True # Workspace for function arcpy.env.workspace = r"C:\Users\user\Documents\Delta State\GIS 470\Week 5\Loop\Data\scratch.mdb" # List of feature classes in scratch.mdb fcList = arcpy.ListFeatureClasses("*USA") # For USA feature classes, add "Cohort" field for fc in fcList: openYear=fc[12:16] closeYear=fc[20:24] # Add "Cohort" field to *USA feature classes in scratch.mdb print fc arcpy.AddField_management(fc, "Cohort", "TEXT") print "Cohort added." # Calculate "Cohort" field to match feature class name in scratch.mdb arcpy.CalculateField_management(fc, "Cohort", expression="""openYear + " to " + closeYear""") print "Field calculated." print "All fields added. All fields calculated."

أكثر...
 
أعلى