Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Delete dbf fields

$
0
0
I have a dbf table with four fields: OID,TYPE,FREQUENCY,COUNT.

I only want to keep TYPE. I got this script off this forum and modified it to fit my data but it is not working. Is that because it is a dbf file? It returns the correct fields for the "print field" command. Any other suggesestions?

Code:

test_dbf = "C:\\TempData\\testdata.dbf"

data_description = arcpy.Describe(test_dbf)
fields = [f.name for f in data_description.fields if f.type not in ["Geometry", "Raster", "Blob"]]

#fields = [f.name for f in arcpy.ListFields(test_dbf)  <> 'Geometry'] # This didn't work either
print fields

for i,f in enumerate(fields):
    if f == 'OID' or f == 'FREQUENCY' or f == 'COUNT':
        del fields[i]

Thank you in advance

Viewing all articles
Browse latest Browse all 2485

Trending Articles