<?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 Concatenating user input into output path/filename in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326452#M25393</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm running a script that takes three pieces of user input, uses those as weights for a raster calcluation, and then saves the output raster layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to use those input values as part of the filename for the output raster, but, unfortunately, I''m not sure how (I copied most of this script from other places).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty sure I need to set the input values as a string (which I have in a comment line), but how do I use those in the final line where I save the output file? Thanks for any help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "C:/GISTemp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#assign variables to raster layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;reduced_west = Raster("reduced_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;offsite_west = Raster("offsite_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;frag_west = Raster("frag_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the parameters from user input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RecoverInput = arcpy.GetParameter(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FragInput = arcpy.GetParameter(1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OffsiteInput = arcpy.GetParameter(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Convert input to percent&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;recoverweight = RecoverInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fragweight = FragInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;offsiteweight = OffsiteInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out Spatial Analyst extension license &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Calculate ouput layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WeightedOutput = ((reduced_west * recoverweight) + (offsite_west * offsiteweight) + (frag_west * fragweight)) / 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# outpath = "C:/GISTemp/ModelOutput/Out_"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# outname = str(RecoverInput) + "_" + str(FragInput) + "_" + str(OffsiteInput)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;WeightedOutput.save("C:/GISTemp/ModelOutput/Out_2")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Sep 2011 21:19:26 GMT</pubDate>
    <dc:creator>BrianCohen</dc:creator>
    <dc:date>2011-09-07T21:19:26Z</dc:date>
    <item>
      <title>Concatenating user input into output path/filename</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326452#M25393</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'm running a script that takes three pieces of user input, uses those as weights for a raster calcluation, and then saves the output raster layer.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'd like to use those input values as part of the filename for the output raster, but, unfortunately, I''m not sure how (I copied most of this script from other places).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm pretty sure I need to set the input values as a string (which I have in a comment line), but how do I use those in the final line where I save the output file? Thanks for any help!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Script:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import arcpy&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy import env&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;from arcpy.sa import *&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#set workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.env.workspace = "C:/GISTemp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#assign variables to raster layers&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;reduced_west = Raster("reduced_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;offsite_west = Raster("offsite_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;frag_west = Raster("frag_west")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the parameters from user input&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RecoverInput = arcpy.GetParameter(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;FragInput = arcpy.GetParameter(1) &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;OffsiteInput = arcpy.GetParameter(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Convert input to percent&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;recoverweight = RecoverInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fragweight = FragInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;offsiteweight = OffsiteInput / 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Check out Spatial Analyst extension license &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CheckOutExtension("Spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Calculate ouput layer&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;WeightedOutput = ((reduced_west * recoverweight) + (offsite_west * offsiteweight) + (frag_west * fragweight)) / 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# outpath = "C:/GISTemp/ModelOutput/Out_"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# outname = str(RecoverInput) + "_" + str(FragInput) + "_" + str(OffsiteInput)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;WeightedOutput.save("C:/GISTemp/ModelOutput/Out_2")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 21:19:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326452#M25393</guid>
      <dc:creator>BrianCohen</dc:creator>
      <dc:date>2011-09-07T21:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating user input into output path/filename</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326453#M25394</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;You are correct that the argument passed to the save function needs to be a string.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is an example of how to create a path and name for your output.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;outpath = "C:/GISTemp/ModelOutput/Out"
outname = �??myRaster�?�
WeightedOutput.save(outpath + os.sep + outname)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;os.sep is the operating system path separator. You will need to import os in you script to us os.sep.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 15:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326453#M25394</guid>
      <dc:creator>TonyPagani</dc:creator>
      <dc:date>2021-12-11T15:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Concatenating user input into output path/filename</title>
      <link>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326454#M25395</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the response Tony. Interestingly, the problem turned out to be that the input values from the user were set as Double, which added a "." to the output path. So making them integers (using the int() function) got rid of that issue and the script worked with just OutRaster.save(pathname + rastername), without need for the os.sep.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks again for the reply!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Sep 2011 17:23:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/concatenating-user-input-into-output-path-filename/m-p/326454#M25395</guid>
      <dc:creator>BrianCohen</dc:creator>
      <dc:date>2011-09-08T17:23:09Z</dc:date>
    </item>
  </channel>
</rss>

