ArcGIS Pro 3.0.0 - using arcpyArcPy
First, I'm very new to coding with pythonPython, so there may be a few mistakes in my code that I am not catching. I'm trying to select each row in a table (line feature class) and save each as it's own feature class using the arcpy.management.SelectLayerByAttribute() tool into a feature database ("Test"). I have a "Long" field titled "Unique_ID" that has numbered the rows from 1 to 291, and I have been trying to use that field to identify and name each row.
**I tried using the Split By Attributes tool, but there is an issue with the format of the output, and I am not able to use the output (not recognized as a feature class) in the next steps. I looked into questions about that tool, but have been unable to resolve it, so I am going this route.
The following is the code I have been working with:
import arcpy
arcpy.env.workspace = "C:/ArcPro_Data/Simp_int_test/Simp_int_test.gdb"
featureclass = "C:/ArcPro_Data/Simp_int_test/Simp_int_test.gdb/Simp_BL_out"
field_bl = [f.name for f in arcpy.ListFields(featureclass, "Un*")]
x=1
with arcpy.da.SearchCursor(featureclass, field_bl) as cursor:
for row in cursor:
new_val = x
express = "Unique_ID = new_val"
layer_out = "C:/ArcPro_Data/Simp_int_test/Simp_int_test.gdb/Test/splitline_" + str(new_val)
arcpy.management.SelectLayerByAttribute(featureclass, "NEW_SELECTION", express)
arcpy.management.CopyFeatures(featureclass, layer_out)
arcpy.management.SelectLayerByAttribute(featureclass, "CLEAR_SELECTION")
x=x+1
The main issue I run into is that the "Unique_ID" field is not found by the program and is returning this error: "ERROR 160144: An expected Field was not found or could not be retrieved properly" for line 11, the Select By Layer Attribute tool.
I noticed that arcpy.ListFields() was returning locations of the fields like this: [<Field object at 0x1b855cadac0[0x1b855ca9f30]>], instead of the actual field name. So, I included .name to list the exact field I want. I am still running into the same error message and I'm not sure how to identify the correct field in the code and use it in the expression in Select Layer By Attribute.
*I also tried new_val = row.getValue(field_bl)
for line 8, and it returns the error: "AttributeError: 'tuple' object has no attribute 'getValue'".