<?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: How to convert arcpy.getparameterastext(0) as integer in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404065#M31825</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What exaclty is the user entering? Why do you split the string input? What do you mean by "I am not getting the desired datatype" - are you writing the value to a field and that is failing?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If they are just entering a number, i.e.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;4568&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;all you have to do is convert from a string to an integer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Pop_option_str = arcpy.GetParameterAsText(0)
Pop_option = int(Pop_option_str)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or to be on the safe side:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Pop_option_str = arcpy.GetParameterAsText(0)
try: Pop_option = int(Pop_option_str) # try conversion
except ValueError: arcpy.AddError('Input was not integer...') # input was invalid...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If they are entering something more complex, you will need to provide more information to us before we can help you...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 18:24:56 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-11T18:24:56Z</dc:date>
    <item>
      <title>How to convert arcpy.getparameterastext(0) as integer</title>
      <link>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404064#M31824</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi All,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp; I am getting the user input using the below statment.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pop_option = arcpy.GetParameterAsText(0)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; I am trying to utilise this input value for my business logic. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; For this I have treat it as integer. So I have tried to convert this value into integer using below statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Pop_option = int(Pop_option)&amp;nbsp;&amp;nbsp; and Pop_option = Pop_option.split(";")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;But i am not getting desired datatype.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Can anyone help me on this??&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 30 Jul 2011 17:51:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404064#M31824</guid>
      <dc:creator>SreenivasaRaoPigili</dc:creator>
      <dc:date>2011-07-30T17:51:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert arcpy.getparameterastext(0) as integer</title>
      <link>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404065#M31825</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;What exaclty is the user entering? Why do you split the string input? What do you mean by "I am not getting the desired datatype" - are you writing the value to a field and that is failing?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If they are just entering a number, i.e.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;4568&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;all you have to do is convert from a string to an integer:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Pop_option_str = arcpy.GetParameterAsText(0)
Pop_option = int(Pop_option_str)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;or to be on the safe side:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Pop_option_str = arcpy.GetParameterAsText(0)
try: Pop_option = int(Pop_option_str) # try conversion
except ValueError: arcpy.AddError('Input was not integer...') # input was invalid...&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If they are entering something more complex, you will need to provide more information to us before we can help you...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:24:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404065#M31825</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-11T18:24:56Z</dc:date>
    </item>
    <item>
      <title>Re: How to convert arcpy.getparameterastext(0) as integer</title>
      <link>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404066#M31826</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It sounds like you are expecting a multi-value parameter (e.g. '123;234;345').&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In this case you can use list comprehensions, the map() function or a loop:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#List comprehension:
Pop_options = [int(p) for p in Pop_option.split(";")]

#Map function
Pop_options = map(int, Pop_option.split(';'))

#Loop
Pop_options=[]
for p in Pop_option.split(';'):
&amp;nbsp;&amp;nbsp;&amp;nbsp; Pop_options.append(int(p))
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 18:24:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-convert-arcpy-getparameterastext-0-as/m-p/404066#M31826</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T18:24:59Z</dc:date>
    </item>
  </channel>
</rss>

