For clarity, I'll post below your code with modifications we discussed - I didn't test it, that's up to you. Note that this is certainly not the only way to perform your desired task. One more thing - check your Date in the script file header -- I am assuming you intend this to be a 'created' date and to have this completed this year, not 2015?##Script Name: calculate sum ##Description: calculate sum of merged range sizes of a taxonomy of migratory birds ##Created By: Elaine Kuo ##Date: 07/18/2015 #Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) #Set the workspace. gp.Workspace= "H:/temp_D/test_1" #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp_D/test" #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Loop through every item in the list that was just generated for fc in fcs: # Break out the name, no path or extension, using the describe object. desc = gp.describe(fc) featureName = desc.name # Add a field to this shapefile, of type LONG gp.AddField (fc, "All", "Long", 10,10) # Make temporary featureclasses gp.MakeFeatureLayer(fc,"lyr") # Get a list of the fields in the featureclass fields = gp.ListFields("lyr", "D*", "Long") # Loop through every item in the list that was just generated for field in fields: # Select records to use in a field calculation (C*, i.e. C7658) query = "\"%s\" = 1" % field.Name gp.SelectLayerByAttribute_management("lyr", "ADD_TO_SELECTION", query) # code the 'All' field of the net selected set with a value of 1 gp.CalculateField_management("lyr", "All", "1", "PYTHON_9.3") gp.SelectLayerByAttribute_management("lyr", "SWITCH_SELECTION") gp.CalculateField_management("lyr", "All", "0", "PYTHON_9.3") #Validate the new feature class name for the output workspace. #OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace) # clear memory of layers gp.Delete("lyr") gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Careful with indention, easy to make an error there!Enjoy,Wayne