Hi everyone,
I'm writing a script to plot points and then delete rows that have a value of less than 5.
I am getting the following error on the cursor lines:
Traceback (most recent call last):
File "C:\Users\30030839\Favorites\Downloads\pyfinal2.py", line 32, in <module>
cursor = arcpy.da.UpdateCursor("C:\\Users\\30030839\\Desktop\\Python\\capacity_points_layer2", ["DEM"])
RuntimeError: cannot open 'C:\Users\30030839\Desktop\Python\capacity_points_layer2'
I'm not sure why this file isn't able to open. It's not being used in any application, and its folder is not open.I added the file to ArcMap previously to make sure the shapefile worked and that the attribute table exists, and it's fine. Does anyone know why I would be getting this error?
So, what is this layer you are trying to run an update cursor on?
cursor = arcpy.da.UpdateCursor("C:\\Users\\30030839\\Desktop\\Python\\capacity_points_layer2", ["DEM"])
It is not a shapefile, nor anything in a file geodatabase, so what is it and does it exist.
Well, then it should have ".lyr" on the end as the extension. Do yourself a favour and in the file explorer, view setting untick to options which says "hide extensions for known file types".
But, I think an update cursor should be run on the data itself. Not a layer file which is a superset (including defrinitions and symbology) and a pointer to the data itself.
So, where is the feature you are trying to update and what is it?
The feature I am trying to update is saved in this path on my computer: C:
Users
30030839
Desktop
Python
capacity_points_layer2.lyr
It is a point shapefile. I have attached the point shapefile if that helps.
Regards,
Alysa Ochoa | Reporting Specialist, Business Intelligence | Bright Horizons Family Solutions | Phone: 720.644.2040 | alysa.ochoa@brighthorizons.com<mailto:alysa.ochoa@brighthorizons.com> | 2655 W. Midway Blvd., Suite 330 | Broomfield, CO 80020
Can you post the updated code, please?
Here is the updated script. I have tested ALL other parts of the script and it works. Just the cursor is not working.
According to this source from Esri, I should be able to just reference the layer to update the rows in the table. UpdateCursor—ArcPy Functions | ArcGIS for Desktop
Rather than pointing the cursor to the .lyr file, can you try pointing it to the feature class that the .lyr refers to?
Try this:
with arcpy.da.UpdateCursor(newLayer, [field1]) as cursor:
Put the field variable in brackets.