My question is similar to that I asked here. The script below, however, is intended to delete unnecessary fields from a single standalone table rather than a database full of tables. The answer in the question referenced above has not performed consistently and I am thinking narrowing it down to a single table may provide some insight to why this is so.
import arcpy
from arcpy import env
table_name = (r'C:\MyDatabase.gdb\StandAloneTable')
field_names = [f.name for f in arcpy.ListFields(table_name) if not f.required]
keep = True
with arcpy.da.SearchCursor(table_name, field_names) as cursor:
for row in cursor:
v = row[0]
if v is None or isinstance(v, basestring) and \
(v == '<Null>' or \
v == 0 or \
v == '' or \
v == ' ' or \
v == ' '):
keep = False
break
if keep is False:
arcpy.DeleteField_management(table_name, field_names)
This script runs without error aside from failing to delete the fields populated only with the values identified in first if-statement as I had intended. No fields are being deleted. Any ideas on what I am doing wrong?
Also, while I am testing this script on standalone tables within a file GDB, the standalone tables I plan to eventually run this script for are housed within an ArcSDE geodatabase.