<?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.GetArgumentCount() doesn�??t count the correct number of arguments passed. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693323#M53777</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Optional parameters are passed as a # character so that place counting is preserved.&lt;BR /&gt;So you could test for the value being == '#' to see if it was not set.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's what I thought and what I remember from ArcGIS 9x, but it seems to be empty strings now not '#'.&amp;nbsp; Actually, I just tested this and it's an empy string '' when using GetParameterAsText(n) and '#' when using sys.argv&lt;N&gt;&lt;/N&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a script tool with 3 parameters, 2 optional (and not entered when I ran it).&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys,arcpy
for i,arg in enumerate(sys.argv[1:]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("argv %s=%s"%(i,repr(arg)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("param %s=%s"%(i,repr(arcpy.GetParameterAsText(i))))
&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Executing: Script Layer1 # #
Start Time: Mon May 14 12:33:51 2012
Running script Script...
argv 0='Layer1'
param 0=u'Layer1'
argv 1='#'
param 1=''
argv 2='#'
param 2=''
Completed script Script...
Succeeded at Mon May 14 12:33:52 2012 (Elapsed Time: 1.00 seconds)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:10:44 GMT</pubDate>
    <dc:creator>Luke_Pinner</dc:creator>
    <dc:date>2021-12-12T05:10:44Z</dc:date>
    <item>
      <title>arcpy.GetArgumentCount() doesn???t count the correct number of arguments passed.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693320#M53774</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a script that works perfect in python, but isn???t working correctly as a script tool in ArcCatalog.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have 3 arcpy.GetParameterAsText arguments, two required and one optional.&amp;nbsp; When I run the script in python it&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;prints the correct number of arguments.&amp;nbsp; When I run it in the script tool it prints the count at 3, if I pass 2 or 3.&amp;nbsp; I&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;am trying to have it run some steps if the count is 2, and more steps if the count is 3.&amp;nbsp; The problem is that it returns the&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;count of 3 every time.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#Get the name and path of the Enterprise Geodatabase&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ws = arcpy.GetParameterAsText(0)&amp;nbsp; #required&amp;nbsp;&amp;nbsp; In the script tool this parameter is a Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;fullPathName = arcpy.GetParameterAsText(1)&amp;nbsp; #The full path name of the output file geodatabase (required)&amp;nbsp; In the script tool this parameter is a Workspace&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;litName = arcpy.GetParameterAsText(2) #Optional The three letter code for records in a field.&amp;nbsp; In the script tool this parameter is a String&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pCount = arcpy.GetArgumentCount()&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.AddMessage(pCount)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;if pCount == 2:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do things&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; do other things&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The add messages shows a count of 3 every time.&amp;nbsp; If I can't get the GetArgumentCount() to return the correct number of passed arguments, I'm at a loss of what to do.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 02 May 2012 23:07:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693320#M53774</guid>
      <dc:creator>BrianHickinbotham</dc:creator>
      <dc:date>2012-05-02T23:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetArgumentCount() doesn�??t count the correct number of arguments passed.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693321#M53775</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;When run as a script tool, arcpy passes empty optional arguments as empty strings (i.e. '').&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Test this with:&lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;litName = arcpy.GetParameterAsText(2) #Optional The three letter code for records in a field. In the script tool this parameter is a String

pCount = arcpy.GetArgumentCount()

if pCount == 2 or not litName:
&amp;nbsp;&amp;nbsp;&amp;nbsp; do things
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; do other things&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;PS: please use CODE tags when posting code - &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/48475-Please-read-How-to-post-Python-code" rel="nofollow noopener noreferrer" target="_blank"&gt;http://forums.arcgis.com/threads/48475-Please-read-How-to-post-Python-code&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:10:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693321#M53775</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T05:10:41Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetArgumentCount() doesn�??t count the correct number of arguments passed.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693322#M53776</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Optional parameters are passed as a # character so that place counting is preserved.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;So you could test for the value being == '#' to see if it was not set.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 13 May 2012 20:32:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693322#M53776</guid>
      <dc:creator>KimOllivier</dc:creator>
      <dc:date>2012-05-13T20:32:44Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.GetArgumentCount() doesn�??t count the correct number of arguments passed.</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693323#M53777</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Optional parameters are passed as a # character so that place counting is preserved.&lt;BR /&gt;So you could test for the value being == '#' to see if it was not set.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's what I thought and what I remember from ArcGIS 9x, but it seems to be empty strings now not '#'.&amp;nbsp; Actually, I just tested this and it's an empy string '' when using GetParameterAsText(n) and '#' when using sys.argv&lt;N&gt;&lt;/N&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For a script tool with 3 parameters, 2 optional (and not entered when I ran it).&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import sys,arcpy
for i,arg in enumerate(sys.argv[1:]):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("argv %s=%s"%(i,repr(arg)))
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("param %s=%s"%(i,repr(arcpy.GetParameterAsText(i))))
&lt;/PRE&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;Executing: Script Layer1 # #
Start Time: Mon May 14 12:33:51 2012
Running script Script...
argv 0='Layer1'
param 0=u'Layer1'
argv 1='#'
param 1=''
argv 2='#'
param 2=''
Completed script Script...
Succeeded at Mon May 14 12:33:52 2012 (Elapsed Time: 1.00 seconds)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:10:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-getargumentcount-doesn-t-count-the-correct/m-p/693323#M53777</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-12T05:10:44Z</dc:date>
    </item>
  </channel>
</rss>

