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)
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.
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' ...
Signed in members can post, follow updates, and more. New here? Register a free account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.