<?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: arcpy.GetParameterAsText to get a list of numbers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450506#M35308</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I assume this is happening because your parameter is a string, and in python strings are lists themselves (lists of characters). A better way to attack this would be to use the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/release/2.6.7/library/stdtypes.html?highlight=split#str.split" rel="nofollow noopener noreferrer" target="_blank"&gt;split function&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;thresholdlist = arcpy.GetParameterAsText(2)
splitthreshold = thresholdlist.split(",")
for threshold in splitthreshold:
...&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 20:06:55 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2021-12-11T20:06:55Z</dc:date>
    <item>
      <title>arcpy.GetParameterAsText to get a list of numbers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450505#M35307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm new to python. I'd like to get a list of numbers (different flow accumulation thresholds for stream extraction) using arcpy.GetParameterAsText and then loop through the list, the relevant part of the code goes like this: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;thresholdlist = arcpy.GetParameterAsText(2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for threshold in thresholdlist:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; out_shp = out_prefix + threshold&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if not arcpy.Exists(out_shp):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.gp.StreamToFeature_sa(strm, fdir, out_shp, "SIMPLIFY")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But when I enter &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;25, 35, 45&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;it seems it is taking one character at a time, because it create out2 and out5, then I got error&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;lt;class 'arcgisscriptin.ExecuteError'&amp;gt;: ERORR 000582: Error occurred during execution.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am running ArcGIS 10 and I am running it as tool. Any suggestions/ideas? Many thanks!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Wei&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Jun 2011 19:04:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450505#M35307</guid>
      <dc:creator>WeiLuo</dc:creator>
      <dc:date>2011-06-10T19:04:45Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetParameterAsText to get a list of numbers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450506#M35308</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I assume this is happening because your parameter is a string, and in python strings are lists themselves (lists of characters). A better way to attack this would be to use the &lt;/SPAN&gt;&lt;A href="http://docs.python.org/release/2.6.7/library/stdtypes.html?highlight=split#str.split" rel="nofollow noopener noreferrer" target="_blank"&gt;split function&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;thresholdlist = arcpy.GetParameterAsText(2)
splitthreshold = thresholdlist.split(",")
for threshold in splitthreshold:
...&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:06:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450506#M35308</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-12-11T20:06:55Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetParameterAsText to get a list of numbers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450507#M35309</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you need to use those values as integers and not strings, you can use this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;thresholdlist = arcpy.GetParameterAsText(2)
splitthreshold = [int(x) for x in thresholdlist.split(',')]
for threshold in splitthreshold:
...&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;See 'List Comprehensions' in the Python documentation for an explanation&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:06:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450507#M35309</guid>
      <dc:creator>BruceNielsen</dc:creator>
      <dc:date>2021-12-11T20:06:58Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetParameterAsText to get a list of numbers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450508#M35310</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;If you need to use those values as integers and not strings, you can use this:&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;thresholdlist = arcpy.GetParameterAsText(2)
splitthreshold = [int(x) for x in thresholdlist.split(',')]
for threshold in splitthreshold:
...&lt;/PRE&gt;&lt;BR /&gt;See 'List Comprehensions' in the Python documentation for an explanation&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Great! Thanks! It worked!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:07:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450508#M35310</guid>
      <dc:creator>WeiLuo</dc:creator>
      <dc:date>2021-12-11T20:07:00Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetParameterAsText to get a list of numbers</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450509#M35311</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am running ArcGIS 10 and I am running it as tool. Any suggestions/ideas? &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you are running is a tool, you may want to make the input a multi-value integer. Then as the user enters them one a time in a dialog, they are all checked to be integers (within a domain that you can specify, for example, the tool won't accept negative numbers). This is really nice because you can do error checking before your tool even sees it, saving you script coding!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If you do it this way, the list comes across as a ';'-delimited string, so you need to split it this way:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;strList = gp.GetParameterAsText(2)
lstNums = strList.split(';')&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If the parameter is strings that may have quotes or ';' within the data values, you may need to get a little fancier with the "list comprehensions" mentioned in this thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 20:07:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getparameterastext-to-get-a-list-of-numbers/m-p/450509#M35311</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T20:07:03Z</dc:date>
    </item>
  </channel>
</rss>

