Hello I have a loop in which if the statement is TRUE I want to delete the last element and add the new. I am posting a part of the code because as many times I tried it, still it doesn't delete the shp and the rasters. Any help is much appreciated. Thanks
elif arithmos >= valueslist[num_pnts2 - 1]: OM = n - 1 #VIEWSHED = "view" + str(OM) #POINT = "point" + str(OM) + ".shp" arcpy.Delete_management("point" + str(OM) + ".shp", "") arcpy.Delete_management("view" + str(OM), "")
In a few words at this part of the code, the last element will be for n=4 ,view4 and I want to delete the (OM = 4-1 => OM = 3) view3.
Got an idea.... use the delete management tool... manually... the go to the Results window, copy the syntax and you will have the required syntax for the script. You will continue to spin your wheels until you get a real copy of what actually works. If you can't delete it manually, then you will have an error message...that would be just as good, then you would know why you cant delete them. So the rule...do it manually once, using the tools, learn/get the syntax from Results and incorporate what it says works, not what we frail humans think should work.
Mr. Patterson this is what I get if I do it manually
<Result 'true'>. I have no idea what that means but it doesn't delete anything. I tried also to pass the name to a variable and put the variable at Delete_management but with no result also. What can be reason for that?
copy the section of the result window...it reveals more than that by many lines
see this
Using the Results window—Help | ArcGIS for Desktop
you can expand the sections and do a screen grab and/or copy to get the full results of the process
I suggest adding a print statement to make sure you are getting to the elif, and print what you are trying to delete. Let the variable populate to the filename, and then
print(VIEW SHED
print(POINT)
you can also include
arcpy.Exists option to make sure it find the file before you try to delete.
sorry, restricted on formatting my response right now.
arcpy.env.workspace = r'<some path/directory>' elif arithmos >= valueslist[num_pnts2 - 1]: OM = n - 1 featureclasses = arcpy.ListFeatureClasses("point" + str(OM) + ".shp") rasters = arcpy.ListRasters("view" + str(OM)) for f in featureclasses: arcpy.Delete_management(f) for r in rasters: arcpy.Delete_management(r)