AnsweredAssumed Answered

Add fields where field names are stored in a list - Python

Question asked by rbasaria_DTS on Sep 19, 2018
Latest reply on Sep 19, 2018 by rbasaria_DTS



I have been working on a tool that does a bunch of stuff, but the piece I am currently stuck on is getting the script to create fields where the field names are stored in a list, and the list is created using an already existing feature class. The idea is that the fields will be identical to the existing feature class in order to run the append tool. Here is what I have so far...I am having a hard time figuring out how to tell the script to create the fields based on the items in the fieldnames list using the types in the fieldtypes list.


#Get list of fields and parameters from original FC.
fieldnames = []
fieldtypes = []
fields = arcpy.ListFields(bound)
for field in fields:
for field in fields:
fieldtypes = ["TEXT" if x=="String" else x for x in fieldtypes]
fieldtypes = ["DOUBLE" if x=="Double" else x for x in fieldtypes]

#Add fields from list with field types.
for field in fieldnames:
    arcpy.AddField_management(newfc,, field.type, "", "", "", "", "", "", "")