-
-
Save jannefleischer/07b94c52b5d33f829ba7633fcd2c41d8 to your computer and use it in GitHub Desktop.
RuntimeError: A column was specified that does not exist. How to find which field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#: the fields in the feature class | |
actual = set([str(x.name) for x in arcpy.ListFields(r'')]) | |
#: the fields you are trying to use | |
expected = set([]) | |
fouled_up = expected - actual |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import arcpy | |
import os | |
test_location = 'c:\\temp' | |
gdb_name = 'inspecific_error' | |
gdb_path = os.path.join(test_location, gdb_name) + '.gdb' | |
table_name = 'tell_me_the_column_name' | |
table_path = os.path.join(gdb_path, table_name) | |
fouled_up_fields = ['test', 'this_one'] | |
if not os.path.exists(test_location): | |
os.makedirs(test_location) | |
arcpy.CreateFileGDB_management(test_location, gdb_name, 'CURRENT') | |
arcpy.CreateTable_management(gdb_path, table_name) | |
arcpy.AddField_management(table_path, 'test', 'TEXT') | |
try: | |
with arcpy.da.SearchCursor(table_path, fouled_up_fields) as cursor: | |
for row in cursor: | |
continue | |
except RuntimeError as e: | |
print 'tell me which one is missing!!' | |
print e | |
print 'oh thanks, not useful' | |
#: the fields in the feature class | |
actual = set([str(x.name) for x in arcpy.ListFields(table_path)]) | |
#: the fields you are trying to use | |
my_silly_input = set(fouled_up_fields) | |
missing = my_silly_input - actual | |
print 'the fouled up columns are {}'.format(missing) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment