I'm trying to add multiple fields to a table using arcpy and am wondering if it's possible to have multiple fields declared in the AddField management, and their values, separated by commas or something? Here is the code as stands, which is slightly cumbersome:
import arcpy, sys
arcpy.env.workspace = "C:\\gislab2\\Python\\take_home"
shapefile = "USCancer2000.shp"
#Set fieldname variables
field_name1 = "Crdrt"
field_name2 = "Crdrt_min"
field_name3 = "Crdrt_max"
field_name4 = "Ageadj"
field_name5 = "MinAgeAdj"
field_name6 = "MaxAgeAdj"
###Declare each standard population per age group, and for summed standard population
Pop1Stnd=78784000
Pop2Stnd=150486000
Pop3Stnd=45364000
TotalStnd=274634000
#Add the fields one at a time
arcpy.AddField_management(shapefile,field_name1,"DOUBLE",
"5","4","","","NULLABLE","NON_REQUIRED","")
arcpy.AddField_management(shapefile,field_name2,"DOUBLE", "5","4","","","NULLABLE","NON_REQUIRED","")
arcpy.AddField_management(shapefile,field_name3,"DOUBLE", "5","4","","","NULLABLE","NON_REQUIRED","")
arcpy.AddField_management(shapefile,field_name4,"DOUBLE", "5","4","","","NULLABLE","NON_REQUIRED","")
arcpy.AddField_management(shapefile,field_name5,"DOUBLE", "5","4","","","NULLABLE","NON_REQUIRED","")
arcpy.AddField_management(shapefile,field_name6,"DOUBLE", "5","4","","","NULLABLE","NON_REQUIRED","")
I know there's a way to create a loop to do it, but was wondering if there was a simpler and more direct way.
No comments:
Post a Comment