I am running a script that was exported directly from model builder in Pro. It runs this select by attributes statement and gives me an error.
# Process: Select Layer By Attribute (Select Layer By Attribute)
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'", invert_where_clause="")
Traceback (most recent call last):
File "H:\Python\HydrantRepairPro.py", line 25, in <module>
Model()
File "H:\Python\HydrantRepairPro.py", line 16, in Model
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'", invert_where_clause="")
TypeError: SelectLayerByAttribute() got an unexpected keyword argument 'invert_where_clause'
Does anyone know why the invert where cause is throwing an error?
Are you using Pro? The parameter in question is only supported in Pro.
I built the model in pro and exported to a python script that I need to run as a scheduled task. When I tried to run the script in IDLE it gave me the error.
The options for that parameter are
inert_where_clause (Optional) | Specifies whether the result of the expression should be inverted.
|
not "". Leave it out altogether if NON_INVERT is what you want. You don't need to specify parameters if you are using named parameters and using defaults.
Dan,
I removed the invert clause statement so not it looks like this:
# Process: Select Layer By Attribute (Select Layer By Attribute)
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'")
Now it gives me this error:
Traceback (most recent call last):
File "H:\Python\HydrantRepairPro.py", line 25, in <module>
Model()
File "H:\Python\HydrantRepairPro.py", line 16, in Model
DBO_wHydrantInspection_Layer, Count = arcpy.SelectLayerByAttribute_management(in_layer_or_view=GISDefault_DBO_wHydrantInspection, selection_type="NEW_SELECTION", where_clause="REPAIR = 'Yes'")
File "C:\Program Files (x86)\ArcGIS\Desktop10.7\ArcPy\arcpy\management.py", line 7737, in SelectLayerByAttribute
raise e
ExecuteError: Failed to execute. Parameters are not valid.
The value cannot be a feature class
ERROR 000840: The value is not a Raster Layer.
ERROR 000840: The value is not a Mosaic Layer.
Failed to execute (SelectLayerByAttribute).
I think you need to add a make feature layer step in there. This is a case where the model to python conversion isn't 100%.
This line in the error is the kicker:
The value cannot be a feature class
As an FYI, the trackback is showing you are running the code from ArcGIS Desktop/ArcMap and not Pro, which is why your original code failed because of the parameter difference. Also, it could be why the code is failing now since Select Layer By Attribute handled data set inputs differently between ArcMap and Pro.
Run the original code from Python bundled with Pro.