<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: invalid syntax:  MakeFeatureLayer_management in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1289#M153</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I may be wrong but is the line 9 actually referring to your print statement?&amp;nbsp; I don't usually run code this way but I think you could confirm the suspicion by running without the try-except block...run the code statements directly, or if that isn't it, check your lyr references to make sure they're valid, although I pretty certain you'd get a different error intead of a 'parsing' error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE:&amp;nbsp; Okay, I was curious to fiddle around with this some more and it seems you have an indention error with 'except' -- in my app, if typing in the commands manually, I have to backspace 4 spaces to 'align' the try/except....essentially this tells the interpreter that the 'except' block is beginning, that the 'try' block has ended.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really didn't know this until I tried loading a script and noticed the left justification.&amp;nbsp; It may be more intuitive to write your script using IDLE and save it to a py file, then load it into the Python window by right-clicking in the window and navigating to where you saved your py file and selecting to open it...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't do it this way, but it may provide a more interactive experience for you, and it's nice to know I have that option.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 17 May 2013 13:19:58 GMT</pubDate>
    <dc:creator>T__WayneWhitley</dc:creator>
    <dc:date>2013-05-17T13:19:58Z</dc:date>
    <item>
      <title>invalid syntax:  MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1288#M152</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Have both the streams and schools layers in my active arcmap session.&amp;nbsp; I am using arcmap's Python window to run this script in a python tutorial that finds schools within a specified distance from streams.&amp;nbsp; Here's the code, error is on line 9:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;gt;&amp;gt;&amp;gt; try:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streams = "Streams.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streamBuffer = "StreamsBuffer.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = "2640 Feet"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; schools2mile = "Schools.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Error'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Parsing error SyntaxError: invalid syntax (line 9)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 11:54:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1288#M152</guid>
      <dc:creator>DamonOsbourne</dc:creator>
      <dc:date>2013-05-17T11:54:56Z</dc:date>
    </item>
    <item>
      <title>Re: invalid syntax:  MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1289#M153</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I may be wrong but is the line 9 actually referring to your print statement?&amp;nbsp; I don't usually run code this way but I think you could confirm the suspicion by running without the try-except block...run the code statements directly, or if that isn't it, check your lyr references to make sure they're valid, although I pretty certain you'd get a different error intead of a 'parsing' error.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope that helps,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;NOTE:&amp;nbsp; Okay, I was curious to fiddle around with this some more and it seems you have an indention error with 'except' -- in my app, if typing in the commands manually, I have to backspace 4 spaces to 'align' the try/except....essentially this tells the interpreter that the 'except' block is beginning, that the 'try' block has ended.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I really didn't know this until I tried loading a script and noticed the left justification.&amp;nbsp; It may be more intuitive to write your script using IDLE and save it to a py file, then load it into the Python window by right-clicking in the window and navigating to where you saved your py file and selecting to open it...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't do it this way, but it may provide a more interactive experience for you, and it's nice to know I have that option.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 May 2013 13:19:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1289#M153</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-05-17T13:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: invalid syntax:  MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1290#M154</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Writing the script in IDLE first and then loading it was a great idea.&amp;nbsp; Made it much easier to troubleshoot.&amp;nbsp; 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.&amp;nbsp; Thanks for the idea, will load all future scripts through idle for just this reason.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 18 May 2013 02:28:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1290#M154</guid>
      <dc:creator>DamonOsbourne</dc:creator>
      <dc:date>2013-05-18T02:28:10Z</dc:date>
    </item>
    <item>
      <title>Re: invalid syntax:  MakeFeatureLayer_management</title>
      <link>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1291#M155</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; 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:&amp;nbsp; &lt;BR /&gt; &lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
&amp;gt;&amp;gt;&amp;gt; try:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streams = "Streams.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streamBuffer = "StreamsBuffer.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = "2640 Feet"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; schools2mile = "Schools.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; except:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Error'
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Parsing error SyntaxError: invalid syntax (line 9)&lt;/PRE&gt; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; 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.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As Wayne noted, your ArcMap python window version failed because you didn't indent it properly in, you guessed it, line 9. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's your indentation, fixed:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
&amp;gt;&amp;gt;&amp;gt; arcpy.env.workspace = "c:/GIS/Python/data/TravisCounty"
&amp;gt;&amp;gt;&amp;gt; try:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streams = "Streams.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; streamBuffer = "StreamsBuffer.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; distance = "2640 Feet"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; schools2mile = "Schools.shp"
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Buffer_analysis(streams,streamBuffer,distance,'FULL','ROUND','ALL')
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.MakeFeatureLayer_management(schools2mile,'Schools2Mile_lyr')
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByLocation_management('Schools2Mile_lyr','intersect',streamBuffer)
&lt;SPAN style="color:&amp;quot;#FF0000&amp;quot;;"&gt;... except:
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'Error'&lt;/SPAN&gt;
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:04:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/invalid-syntax-nbsp-makefeaturelayer-management/m-p/1291#M155</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-10T20:04:15Z</dc:date>
    </item>
  </channel>
</rss>

