Problem with Delete Field

745
3
01-17-2011 06:43 AM
DanielDillard
New Contributor II
Hi all,

I am attempting to delete fields from a result table of the ZoneStatisticsAsTable tool.

Here is the script in python:

import arcgisscripting

gp = arcgisscripting.create(9.3)

table = "C:\GISDATA\resultTable"

fields = gp.ListFields(resultTable)

for field in fields:
    if ((field.name != "BUILD_ID") and (field.name != "MAX")):
        gp.deletefield(table, field)


I get:

RuntimeError: Object: Error in executing tool.

I tried running the deleteField tool on the same table in the command line in ArcMap and got an error saying the table does not exist or is not supported. 

I am able to manually delete fields on this table in ArcMap.

At this point I am going to find another way to accomplish my goal.  I am just curious as to why this isn't working.
0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus
table = "C:\GISDATA\resultTable"

is incorrect, it must be
table = r"C:\GISDATA\resultTable"
or
table = "C:\\GISDATA\\resultTable"
or
table = "C:/GISDATA/resultTable"
and I suspect that a file extension is also needed
0 Kudos
ColinZwicker
Esri Contributor

I think you will also then need to pass that to the list fields

fields = gp.ListFields(table)

instead of

fields = gp.ListFields(resultTable)

note: if that table is a shapefile attempting to delete a required field (e.g., FID) should also fail.

0 Kudos
DanPatterson_Retired
MVP Emeritus

Well after 6 years I doubt he care... and just incase anyone forgets to use raw string formatting when using python, here is what happens

>>> table = "C:\GISDATA\resultTable"
>>> print(table)
esultTable

No wonder the table couldn't be found

0 Kudos