I'm very new to using python and figure I'm missing something obvious in the following script. I keep getting a "syntax error" message no matter how much I fiddle around with the first few lines. I think it has something to do with calling the spatial analyst module into python while checking out the spatial analyst extension.

#Script takes an input DEM raster and delineates watershed boundaries based on
# flow direction and accumulation

# Import arcpy module
import arcpy
from arcpy.sa import *
arcpy.env.overwriteOutput = True

# Check out the Spatial Analyst extension

#Specify the input raster
inDEM = arcpy.GetParameterAsText(0)

#Specify the input coordinate system
spatialReference = arcpy.GetParameterAsText(1)

#Specify the minimum number of cells that are assumed to represent a stream
# (cell threshold)
inMin = arcpy.GetParameterAsText(2)

    # Process: Project Raster
    arcpy.ProjectRaster_management(inDEM, projectDEM, spatialReference)

    # Process: Fill
    fillDEM = Fill(projectDEM)

    # Process: Flow Direction
    flowDir = FlowDirection(fillDEM, "NORMAL")

    # Process: Flow Accumulation
    flowAccum = FlowAccumulation(flowDir)

    # Process: Raster Calculator
    outRaster = RasterCalculator((flowAccum > inMin))

    # Process: Raster to Polyline
    arcpy.RasterToPolyline_conversion(outRaster, polyLines, "ZERO", "0", "SIMPLIFY", "VALUE")

    # Process: Feature Vertices To Points
    arcpy.FeatureVerticesToPoints_management(polyLines, lineVertices, "END")

    # Process: Watershed
    outWatershed = Watershed(flowDir, lineVertices)

    # Process: Raster to Polygon
    arcpy.RasterToPolygon_conversion(outWatershed, watershedPolygons, "SIMPLIFY", "VALUE")

    # Check in the Spatial Analyst extension

#error handling
    arcpy.AddError("Script failed to write successfully")

closed as off-topic by Erica, PolyGeo Dec 21 '14 at 9:56

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions describing a problem that can't be reproduced and seemingly went away on its own (or went away when a typo was fixed) are off-topic as they are unlikely to help future readers." – Erica, PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 1
    Welcome to GIS SE! If you think the error is coming from the first few lines, then would you be able to use the edit button to reduce your code to a snippet of just enough to demonstrate that error, please? Also, can you include the precise error message. – PolyGeo Dec 14 '14 at 21:51
  • Can you confirm that import arcpy is working? Try commenting out everything except that, and running your code. – Stephen Lead Dec 15 '14 at 5:02
  • Try should be try (no cap) – radouxju Dec 15 '14 at 8:10
  • This seems to have been a pure Python problem i.e. incorrect capitalization. – PolyGeo Dec 21 '14 at 9:55

Your Try: statement is capitalised, it should be lower case - try:

Not the answer you're looking for? Browse other questions tagged or ask your own question.