Very simple code, don't understand the error

374
4
Jump to solution
01-30-2018 12:59 PM
DanielSchatt
New Contributor III

hi, just trying to run a simple code:

>>> import arcpy
... arcpy.CheckOutExtension("Spatial")
... arcpy.env.workspace = "C:\stuff\SCHISM_SLR_stuff\Con_Rasters\Con_0625"
... allRasters = arcpy.ListRasters("*","TIF")
... for eachRaster in allRasters:
...    theRaster = Raster(eachRaster)
...    outRaster = 6.25 - theRaster
...    outRaster.save(eachRaster.replace('.tif','_Final.tif'))

The error is:
Runtime error
Traceback (most recent call last):
File "<string>", line 6, in <module>
NameError: name 'Raster' is not defined

Thanks for any help!

Dan

0 Kudos
1 Solution

Accepted Solutions
XanderBakker
Esri Esteemed Contributor

It should be "arcpy.Raster" instead of "Raster"

Also put an r before the workspace location:

arcpy.env.workspace = r"C:\stuff\SCHISM_SLR_stuff\Con_Rasters\Con_0625"

View solution in original post

4 Replies
XanderBakker
Esri Esteemed Contributor

It should be "arcpy.Raster" instead of "Raster"

Also put an r before the workspace location:

arcpy.env.workspace = r"C:\stuff\SCHISM_SLR_stuff\Con_Rasters\Con_0625"
DanielSchatt
New Contributor III

Thanks Xander!

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

What command is "Raster" supposed to be?

0 Kudos
XanderBakker
Esri Esteemed Contributor

It converts a path to a raster into a raster object that allows you to the substract the rasters with the need to use the Minus tool.

0 Kudos