unigisromy

"for" loop does not work with raster List (but it should)

Discussion created by unigisromy on Oct 15, 2011
Latest reply on Oct 22, 2011 by unigisromy
Hello,

I have a quite simple problem but I could not get a pyhton script running...
I want to loop through a list of rasters stored in a GDB. I have reduced my code to a few lines but python exits with a "syntax error, invalid syntax". I tried to do the same with ListFeatureClasses but the code does not work either.

This is what I have done so far:

# Import arcpy module
import arcpy

# Check out any necessary licenses
arcpy.CheckOutExtension("3D")
arcpy.CheckOutExtension("spatial")
arcpy.CheckOutExtension("data management")

env.workspace = "D:\\ArcGIS\\Data\\raster.gdb"

rsList = arcpy.ListRasters("*_temp*","GRID")
print rsList
rsList.sort
print rsList #till this line scipt works fine

for rs in rsList
print rs
arcpy.AddMessage(str(rs))
arcpy.Delete_management(rs)

The code in red does not work... but it should. I´m puzzled. Any Ideas?
Thanks, Romy

Outcomes