Have both the streams and schools layers in my active arcmap session. I am using arcmap's Python window to run this script in a python tutorial that finds schools within a specified distance from streams. Here's the code, error is on line 9:
import arcpy
>>> arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
>>> try:
... streams = "Streams.shp"
... streamBuffer = "StreamsBuffer.shp"
... distance = "2640 Feet"
... schools2mile = "Schools.shp"
... arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
... arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
... arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
... except:
... print 'Error'
...
Parsing error SyntaxError: invalid syntax (line 9)
Turned out the Streams layer wasn't valid for whatever reason, but the error message in the Arcpy window wasn't letting me know it.
As Wayne noted, your ArcMap python window version failed because you didn't indent it properly in, you guessed it, line 9. Using an IDE like IDLE does indeed help with syntax issues like this; the python window is really best for running a single tool or trying out a few lines of code, not for entering/writing scripts. There are many useful IDE's to use -- IDLE is just the one that ships with all Python distributions -- it's the "vi" of Python IDE's - quick, minimal, always there.Here's your indentation, fixed:
import arcpy
>>> arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
>>> try:
... streams = "Streams.shp"
... streamBuffer = "StreamsBuffer.shp"
... distance = "2640 Feet"
... schools2mile = "Schools.shp"
... arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
... arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
... arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
... except:
... print 'Error'
...