<?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: File saving and naming in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385715#M30412</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Curtis and Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, Curtis, I changed the code and and followed the code in your other post. The files are numbered in sequence. Tmax_001, Tmax_002....Tmax_037&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I have to read more about these strings and filenaming techniques in Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 11 Sep 2014 05:55:57 GMT</pubDate>
    <dc:creator>Leo_KrisPalao</dc:creator>
    <dc:date>2014-09-11T05:55:57Z</dc:date>
    <item>
      <title>File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385709#M30406</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Python Users,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to automate my filenaming in my python script. This is what I am doing.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am calculating a bunch of rasters using the implementation of raster calculator / map algebra in python. I want to save my output in this way:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PET_001.tif&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;PET_037.tif&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;here is the script that I am running:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;clim = r'path\to\rasters'&lt;/P&gt;&lt;P&gt;arcpy.env.workspace = clim&lt;/P&gt;&lt;P&gt;clim_rasters = arcpy.ListRasters()&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;for raster in clim_rasters:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmax_ras = arcpy.ListRasters("Tmax*")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; tmin_ras = arcpy.ListRasters("Tmin*")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ra_ras = arcpy.ListRasters("RA*")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; PET5 = 0.0023 * Raster(ra_ras) * ((Raster(tmax_ras) + Raster(tmin_ras) / 2.00) + 17.8) * ((Raster(tmax_ras) + Raster(tmin_ras))**0.5)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I need to save my output in such a way described above. Help please.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 09:41:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385709#M30406</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-08-28T09:41:24Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385710#M30407</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have a look at the CreateUniqueName function:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004v000000" title="http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000004v000000"&gt;ArcGIS Help 10.1&lt;/A&gt; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 28 Aug 2014 10:05:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385710#M30407</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-08-28T10:05:59Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385711#M30408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;or you could have some fun... then don't forget to &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//00p60000000r000000" rel="nofollow noopener noreferrer" target="_blank"&gt;save your raster&amp;nbsp; &lt;/A&gt;&lt;/P&gt;&lt;P&gt;(ie Raster.save(outName)&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;

'''
FileNamesPaddedZeros
padding filenames with zeros
'''


filename = "c:/temp/MyfileName.tif"
basename, extension = filename.split(".")

for i in range(40):
&amp;nbsp; padWith = "%03i." % &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/info.png" /&gt;
&amp;nbsp; outName = basename + "/" + padWith + extension
&amp;nbsp; print outName


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 17:44:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385711#M30408</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2021-12-11T17:44:11Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385712#M30409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Dan and Anthony,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your reply.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way Dan, I tried to copy your code and execute it. If my declared variable in filename is "PET_.tif", it only prints "PET_%03i.tif" and repeat it 40 times.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The padWith variable which is "%03i." % is throwing a syntax error. It is because of the last % character. If I remove the last % character it executes but print statement is like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;PET_%03i.tif"&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;(40 times)&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;PET_%03i.tif"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for any help.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am a just a python newbie and I am learning it through self study and of course through asking in the forum.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 09:33:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385712#M30409</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-08-29T09:33:28Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385713#M30410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You have to give the whole path to the tiff's filename, not the variable name&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 11:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385713#M30410</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-08-29T11:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385714#M30411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;I answered this for you on another post this morning&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;A href="https://community.esri.com/thread/99713"&gt;Run raster calculation on multiple lists of rasters&lt;/A&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;but I think we have another issue here - your code is assuming the ListRasters will only return one raster. Are you sure this is the case?&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&lt;/P&gt;&lt;P style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;How are your data structured? A&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;re these netCDF rasters that have rasters like "Tmax01" inside each raster? &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 29 Aug 2014 17:13:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385714#M30411</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-08-29T17:13:48Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385715#M30412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Curtis and Dan,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for your suggestions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;By the way, Curtis, I changed the code and and followed the code in your other post. The files are numbered in sequence. Tmax_001, Tmax_002....Tmax_037&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I think I have to read more about these strings and filenaming techniques in Python.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;-Leo&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 05:55:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385715#M30412</guid>
      <dc:creator>Leo_KrisPalao</dc:creator>
      <dc:date>2014-09-11T05:55:57Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385716#M30413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;The powerful string manipulation capabilities in Python are one of the things that make it so awesome.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;These arcpy methods are very helpful with file naming as well, especially for temporary files: CreateScratchName, CreateUniqueName, ValidateTableName.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 15:40:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385716#M30413</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2014-09-11T15:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: File saving and naming</title>
      <link>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385717#M30414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;A href="http://mkaz.com/2012/10/10/python-string-format/"&gt;This site&lt;/A&gt; is a good resource for string formatting.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 11 Sep 2014 15:50:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/file-saving-and-naming/m-p/385717#M30414</guid>
      <dc:creator>JeffWard</dc:creator>
      <dc:date>2014-09-11T15:50:37Z</dc:date>
    </item>
  </channel>
</rss>

