<?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: parsing/syntax error using Mosaic to New Raster in loop in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/parsing-syntax-error-using-mosaic-to-new-raster-in/m-p/718993#M55674</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have a few issues. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Change:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import*&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There's no need to use operator.itemgetter, just access the list directly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mosaicNames[count] etc... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This syntax is incorrect:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MosaicToNewRaster_management(raster;habbuf,"C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040", etc.. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pass a list or a semicolon delimited string instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MosaicToNewRaster_management([raster, habbuf,"C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040"], etc...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 27 Apr 2014 00:50:03 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2014-04-27T00:50:03Z</dc:date>
    <item>
      <title>parsing/syntax error using Mosaic to New Raster in loop</title>
      <link>https://community.esri.com/t5/python-questions/parsing-syntax-error-using-mosaic-to-new-raster-in/m-p/718992#M55673</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new to Python coding language, and find myself stuck on what I'm guessing is a straightforward issue.&amp;nbsp; Nonetheless, I've been battling this for 2 days now, and no amount of changes to the syntax nor searching for hints online has lead me to the solution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In short, I am running Arc 10.1 and attempting to script a for loop to process a series of rasters in a directory using the Mosaic to New Raster followed by several manipulations of the subsequent output.&amp;nbsp; I am receiving the error message "Parsing error SyntaxError: invalid syntax (line 7)".&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I understand how Python counts lines of code, this points to the line regarding the Mosaic to New Raster calculation. I've double checked this line against examples from the ArcGIS help pages and from other forums online, and it looks to be properly formatted - but Python does not agree! It could also be the line following the Mosaic to New Raster command, which calls the spatial analyst extension - but that also *seems* to be formatted correctly...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is my code (try not the grimace, I know it's probably pretty rudimentary to you gurus):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import*&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from operator import itemgetter&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;rasterList = arcpy.ListRasters() #list of all rasters in the target folder&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;mosaicNames = ["junkamo", "junkbmo"]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;clipNames = ["junkac", "junkbc"] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;maskNames = ["junkam", "junkbm"] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fragNames = ["junkaf", "junkbf"] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;occNames = ["junkaocc", "junkbocc"] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;habbuf = "C:/Workspace_DSchwalm/GIS/DataLayers/2013_Fragstats/Buffers/romohabbuf"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;for raster in rasterList:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; mosaicName = itemgetter(count)(mosaicNames) #grab desired mosaic raster name from mosaicNames list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; clipName = itemgetter(count)(clipNames)&amp;nbsp; #grab desired clipped raster name from clipNames list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; maskName = itemgetter(count)(maskNames)&amp;nbsp; #grab desired mask raster name from maskNames list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; fragName = itemgetter(count)(fragNames)&amp;nbsp; #grab desired fragstats raster name from fragNames list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; occName = itemgetter(count)(occNames)&amp;nbsp; #grab desired occupancy raster name from occNames list&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.MosaicToNewRaster_management(raster;habbuf,"C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040", mosaicName, "#", "8_BIT_UNSIGNED", "#", "1", "FIRST","FIRST")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; clipName = Times(mosaicName, habbuf)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.gp.Reclassify_sa(clipName,"VALUE","0 0.40000000000000002 NODATA;0.40000000000000002 1 1",maskName,"DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.gp.Reclassify_sa(maskName,"VALUE","1 1;NODATA 0",fragName,"DATA")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; occName = Times(maskName, mosaicName)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; count = count + 1 #advance the count by 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any ideas what is wrong with my syntax, or what other error(s) I've made to generate the "Parsing error SyntaxError: invalid syntax (line 7)" error message? Many thanks in advance, I much appreciate your help getting my past this glitch!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 25 Apr 2014 23:24:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/parsing-syntax-error-using-mosaic-to-new-raster-in/m-p/718992#M55673</guid>
      <dc:creator>DonelleSchwalm</dc:creator>
      <dc:date>2014-04-25T23:24:07Z</dc:date>
    </item>
    <item>
      <title>Re: parsing/syntax error using Mosaic to New Raster in loop</title>
      <link>https://community.esri.com/t5/python-questions/parsing-syntax-error-using-mosaic-to-new-raster-in/m-p/718993#M55674</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You have a few issues. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Change:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import*&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;To&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There's no need to use operator.itemgetter, just access the list directly:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;mosaicNames[count] etc... &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This syntax is incorrect:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MosaicToNewRaster_management(raster;habbuf,"C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040", etc.. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Pass a list or a semicolon delimited string instead:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.MosaicToNewRaster_management([raster, habbuf,"C:/Workspace_DSchwalm/GIS/DataLayers/2014_PredictionGrids/TEST/2011to2040"], etc...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 27 Apr 2014 00:50:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/parsing-syntax-error-using-mosaic-to-new-raster-in/m-p/718993#M55674</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2014-04-27T00:50:03Z</dc:date>
    </item>
  </channel>
</rss>

