<?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: Simple question about using variable in arcpy tools in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122065#M4238</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;outp ut)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CompositeBands_management(red;green;nir,outp ut)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is that a typing or copying error?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 12 Nov 2010 21:16:05 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2010-11-12T21:16:05Z</dc:date>
    <item>
      <title>Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122063#M4236</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all, I am trying to get the following script to work, and don't understand why it won't. Any help would be much appreciated. The first example won't run, the second executes normally, and I need to understand why. I am using the glob and os extensions to try to iterate through a bunch of files, but the tools doesn't seem to like variables.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;example 1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;green = 'N:\\Bhutan\Spatial Data\\ASTER Images\\AST14DMO_V1.tif'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;red = 'N:\\Bhutan\Spatial Data\\ASTER Images\\AST14DMO_V2.tif'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nir = 'N:\\Bhutan\Spatial Data\\ASTER Images\\AST14DMO_V3N.tif'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 'N:\\Bhutan\Spatial Data\\ASTER Images\\Stack1.img'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CompositeBands_management(red;green;nir,output)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or: &amp;lt;arcpy.CompositeBands_management("red;green;nir","output")&amp;gt; Both ways fail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;example 2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CompositeBands_management("N:\\Bhutan\Spatial Data\\ASTER Images\\AST14DMO_V1.tif;N:\\Bhutan\Spatial Data\\ASTER Images\\AST14DMO_V2.tif;N:\\Bhutan\Spatial Data\\ASTER Imagesa\\AST14DMO_V3N.tif","N:\\Bhutan\Spatial Data\\ASTER Images\\Stack.img")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Nov 2010 20:50:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122063#M4236</guid>
      <dc:creator>SeanCook</dc:creator>
      <dc:date>2010-11-12T20:50:20Z</dc:date>
    </item>
    <item>
      <title>Re: Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122064#M4237</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;My error is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000271: Cannot open the input datasets Failed to execute (CompositeBands).&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Nov 2010 20:57:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122064#M4237</guid>
      <dc:creator>SeanCook</dc:creator>
      <dc:date>2010-11-12T20:57:26Z</dc:date>
    </item>
    <item>
      <title>Re: Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122065#M4238</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;outp ut)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;in&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CompositeBands_management(red;green;nir,outp ut)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is that a typing or copying error?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Nov 2010 21:16:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122065#M4238</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2010-11-12T21:16:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122066#M4239</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;red = 'file_red.tif'&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# etc&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;"red;green;nir"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;isn't using the contents of the variables red, green and nir, but the characters r, e, d, and so on, which is not what you want.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;There are sevearal ways to join the contents from a number of strings into a new string. My personal favorit is the str.join method, which is very handy when you have your strings to join in a tuple or list:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;my_strings = (red, green, nir) # first put them in a tuple&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;joined_strings = ';'.join(my_strings) # delimited by ;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Another possibility is to use string formatting:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;joined_strings = '%s;%s;%s' % (red, green, nir)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And yet another way is to use string concatenation as ESRI do in most of their samples:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;joined_strings = red + ';' + green + ';' + 'nir'&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Personally I like the first two, and don't like last. I think concatenation makes the code hard to read.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 13 Nov 2010 03:33:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122066#M4239</guid>
      <dc:creator>NiklasNorrthon</dc:creator>
      <dc:date>2010-11-13T03:33:05Z</dc:date>
    </item>
    <item>
      <title>Re: Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122067#M4240</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Good to remember is that the string formatting method actually works well inside the tool parameters line.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CompositeBands_management('%s,%s,%s' % (red,green,nir) ,output)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Oh and I agree Niklas, concatenation of strings especially if you have a lot of things you are joining, makes your code hard to read.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 15 Nov 2010 12:05:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122067#M4240</guid>
      <dc:creator>ChrisMathers</dc:creator>
      <dc:date>2010-11-15T12:05:42Z</dc:date>
    </item>
    <item>
      <title>Re: Simple question about using variable in arcpy tools</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122068#M4241</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks a bunch guys. Appreciate it!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 16 Nov 2010 20:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-question-about-using-variable-in-arcpy/m-p/122068#M4241</guid>
      <dc:creator>SeanCook</dc:creator>
      <dc:date>2010-11-16T20:44:08Z</dc:date>
    </item>
  </channel>
</rss>

