The feature class used as a template to define the attribute schema of the feature class.Does this include the field order? I ask because the help page for arcpy.da.insertcursor says:
Use an asterisk (*) instead of a list of fields if you want to access all fields from the input table [...]. However, for faster performance and reliable field order,
arcpy.CreateFeatureclass_management( newFCpath, newFCname, "POINT", templateFC, "DISABLED", "DISABLED", templateFC ) newRows = arcpy.da.InsertCursor(newFC, "*") templateRows = arcpy.da.SearchCursor(templateFC, "*") for row in templateRows: newRows.insertRow( row )
Solved! Go to Solution.
templateRows.fields
for index, field in enumerate(templateRows.fields): d[field] = index
for row in templateRows: val = row[d["field_name"]]
arcpy.CreateFeatureclass_management( newFCpath, newFCname, "POINT", templateFC, "DISABLED", "DISABLED", templateFC ) newRows = arcpy.da.InsertCursor(newFC, "*") templateRows = arcpy.da.SearchCursor(templateFC, "*")
templateRows.fields
for index, field in enumerate(templateRows.fields): d[field] = index
for row in templateRows: val = row[d["field_name"]]
templateRows.fields
To bridge the gap that remains you can just make a dictionary of index/field name values to reference the name instead of the index.for index, field in enumerate(templateRows.fields): d[field] = index
So you can do something like this.for row in templateRows: val = row[d["field_name"]]
def main_index(): curs = arcpy.da.SearchCursor(table, '*') t0 = _timer() for row in curs: val1 = row[6] val2 = row[7] t1 = _timer() - t0 index_times.append(t1) print('index time: {0}'.format(t1)) def main_dict(): curs = arcpy.da.SearchCursor(table, '*') t0 = _timer() d = {} for index, field in enumerate(curs.fields): d[field] = index for row in curs: val1 = row[d['POLY_NUM']] val2 = row[d['TYPE']] t1 = _timer() - t0 dict_times.append(t1) print('dict time: {0}'.format(t1))