arcpy.env.overwriteOutput = 1
arcpy.env.overwriteOutput = 1
arcpy.CheckOutExtension('Spatial')
arcpy.env.scratchWorkspace = outPath
arcpy.env.workspace = dataPath
#create a list of rasters in the workspace
rasters = arcpy.ListRasters('','')
i = 0
#loop through rasters in list
for raster in rasters:
print "processing raster: %s" %os.path.join(dataPath,raster)
#convert nodata to zero
out1 = Con(IsNull(raster), 0, raster)
#sum rasters together
if i == 0:
out2 = arcpy.Raster(out1)
i += 1
else:
out2 = out2 + out1
i += 1
#save final output
out.save(os.path.join(outPath,'sumRas'))
rasters = arcpy.ListRasters('','')
rastersum = rasters[0]
for raster in rasters[1:]:
rastersum+=arcpy.Raster(raster)I know this is a bit late but I came across this from google and thought I'd clean up your for loop.
A few comments on your code: