AnsweredAssumed Answered

Looping problems! - Deleting fields

Question asked by matthewrusso on Feb 18, 2015
Latest reply on Feb 18, 2015 by matthewrusso

So I got my script to work but it is still giving me a problem.

 

When i run the script through command line it is printing out the elif clause about 10-15 times each before it starts to delete fields.  Anyone have any advice?

 

import arcpy

fieldList = ['ID','LAT','LON','AREA','PARIMETER','Hectares','CODE',
             'WEBCODE','DATE_','TIME_','SURVEYOR','TYPE','REV_DATE',
             'DATA_SRC','PATTERN','SWATH_DIST','VIEW_DIRC','CONDITIONS',
             'CONFIDENCE','RPT_YR','SURVEY_ID1','SURVEY_ID2','SURVEY_ID3',
             'DMG_TYPE1','DMG_TYPE2','DMG_TYPE3','SEVERITY1','SEVERITY2',
             'SEVERITY3','PATTERN1','PATTERN2','PATTERN3','TPA1', 'TPA2',
             'TPA3','NO_TREES1','NO_TREES2','NO_TREES3','NOTES','NOTE',
             'DAMAGE94_','DAMAGE94_I','STATUS','MODIFIIER','ACRES',
             'PESTNUM','MODNUM','GRP1','GRP2','GRP3','SURVEY_YR','RPT_RGN',
             'R295_DMG_I','R295_DMG_','R2_PC3','R2_PC2','R2_PC1','R201_DMG_',
             'R201_DMG_I','AREA_METER', 'SOURCETHM','PCT_MORT1','PCT_MORT2',
             'PCT_MORT3']
             
arcpy.env.workspace = r'H:\GIS DATA\Data\Pine Beetle\Beetle\Test'
fcs = arcpy.ListFeatureClasses()

for fc in fcs:
    for i in fieldList:
        x = arcpy.ListFields(fc)
        for a in x:
            if i == a.name:
                arcpy.DeleteField_management(fc, i)
                print i + ' was deleted from ' + fc
            elif i != a.name:
                print i

Outcomes