<?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: python loop - saving output in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225430#M17422</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;&lt;STRONG&gt;Code formatting the basics++&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Because it looks off.. and your paths don't look correct to begin with.&amp;nbsp; I would throw some print statements in to get an idea of what the actual inputs and outputs look like&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 17 Dec 2017 20:31:20 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2017-12-17T20:31:20Z</dc:date>
    <item>
      <title>python loop - saving output</title>
      <link>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225429#M17421</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The script is intended to subtract the loop variable from a raster and save the raster using an appropriate name.&lt;/P&gt;&lt;P&gt;I tried quite a few work-arounds, but all methods seem the hit a wall. The attached image shows that the same simple tool in modelbuilde casts the same error.&lt;/P&gt;&lt;P&gt;Anyone that made something similar?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Via this simple python loop:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;import arcpy&lt;BR /&gt;stepper = 5&lt;BR /&gt;for stepper in range (20):&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name="AFVdtm"+str(stepper)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name= arcpy.sa.Minus("DTM_frostkærLocal.tif",stepper)&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; stepper += stepper&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; rod = "c:/testmappe/"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name=name&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; eft=".tif"&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sti=rod+name+eft&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name.save(sti)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;Traceback (most recent call last):&lt;/P&gt;&lt;P&gt;File "&amp;lt;string&amp;gt;", line 10, in &amp;lt;module&amp;gt;&lt;/P&gt;&lt;P&gt;File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Functions.py", line 4331, in Plus&lt;/P&gt;&lt;P&gt;in_raster_or_constant2)&lt;/P&gt;&lt;P&gt;File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Utils.py", line 53, in swapper&lt;/P&gt;&lt;P&gt;result = wrapper(*args, **kwargs)&lt;/P&gt;&lt;P&gt;File "c:\program files\arcgis 2.0\pro\Resources\arcpy\arcpy\sa\Functions.py", line 4328, in Wrapper&lt;/P&gt;&lt;P&gt;["Plus", in_raster_or_constant1, in_raster_or_constant2])&lt;/P&gt;&lt;P&gt;RuntimeError: ERROR 000732: Input Raster: Dataset c:/testmappe/ does not exist or is not supported&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have tried using relative and absolute paths, which doesn't change anything in the error.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Running it like:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #a57946; font-size: xx-small;"&gt;&lt;EM&gt;import&lt;/EM&gt;&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;arcpy&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;STRONG&gt;=&lt;/STRONG&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #b58900; font-size: xx-small;"&gt;5&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style=": ; color: #a57946; font-size: xx-small;"&gt;for&lt;/EM&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;EM style=": ; color: #a57946; font-size: xx-small;"&gt;in&lt;/EM&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;STRONG style=": ; color: #2794d9; font-size: xx-small;"&gt;range&lt;/STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; (&lt;/SPAN&gt;&lt;SPAN style="color: #b58900; font-size: xx-small;"&gt;20&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; name&lt;/SPAN&gt;&lt;STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;=&lt;/SPAN&gt;&lt;SPAN style="color: #b58900; font-size: xx-small;"&gt;"AFVdtm"&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;+&lt;/SPAN&gt;&lt;SPAN style="color: #2794d9; font-size: xx-small;"&gt;str&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;(&lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name&lt;/SPAN&gt;&lt;STRONG style=": ; color: #4a4a4a; font-size: xx-small;"&gt;=&lt;/STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;arcpy.sa.Minus&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;(&lt;/SPAN&gt;&lt;STRONG style=": ; color: #b58900; font-size: xx-small;"&gt;"DTM_frostkærLocal.tif"&lt;/STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;,&lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;) &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;STRONG&gt;+&lt;/STRONG&gt;= &lt;/SPAN&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;stepper&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #2493f2; font-size: xx-small;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; name.save&lt;/SPAN&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;(&lt;/SPAN&gt;&lt;STRONG style=": ; color: #b58900; font-size: xx-small;"&gt;"c:/testmappe/%name%.tif"&lt;/STRONG&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4a4a4a; font-size: xx-small;"&gt;Produces the intended output, but continously overwrites it &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/sad.png" /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Dec 2017 20:24:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225429#M17421</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2017-12-17T20:24:31Z</dc:date>
    </item>
    <item>
      <title>Re: python loop - saving output</title>
      <link>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225430#M17422</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A _jive_internal="true" href="https://community.esri.com/blogs/dan_patterson/2016/08/14/script-formatting"&gt;&lt;STRONG&gt;Code formatting the basics++&amp;nbsp;&lt;/STRONG&gt;&lt;/A&gt;&lt;/P&gt;&lt;P&gt;Because it looks off.. and your paths don't look correct to begin with.&amp;nbsp; I would throw some print statements in to get an idea of what the actual inputs and outputs look like&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Dec 2017 20:31:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225430#M17422</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-12-17T20:31:20Z</dc:date>
    </item>
    <item>
      <title>Re: python loop - saving output</title>
      <link>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225431#M17423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I just updated it, does that help?&lt;/P&gt;&lt;P&gt;Please don't pay attention to indentation, it is obviuosly somethings that happens when pasting.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using the modelbuilder solution I see that Minus/Raster Calculator interpretes the output of the For loop as a string &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&amp;nbsp;Jeez, ESRI.&lt;/P&gt;&lt;P&gt;I edit it to int(%Vakue%) which solves the calculation-part of the problem. Not the saving-part.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Dec 2017 20:38:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225431#M17423</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2017-12-17T20:38:52Z</dc:date>
    </item>
    <item>
      <title>Re: python loop - saving output</title>
      <link>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225432#M17424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;name is still wrong... try to create one using a base name..&amp;nbsp;&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;outName &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"thisfile"&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;then you can append to that file with your stepper&lt;/P&gt;&lt;PRE class="language-python line-numbers"&gt;&lt;CODE&gt;sti &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"/"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;join&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;rod&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; outname&lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt;str&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;stepper&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; eft&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 17 Dec 2017 21:00:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-loop-saving-output/m-p/225432#M17424</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2017-12-17T21:00:40Z</dc:date>
    </item>
  </channel>
</rss>

