<?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 Python Conditional Statement not Working in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745391#M57620</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This should be pretty basic, but for the life of me I can not figure out why this conditional statement doesn't function correctly.&lt;/P&gt;&lt;P&gt;I'm using the count tool to count the # of selected records. If the count = 0, then the user should just get a message that says "No Issues were logged during this walk through." but if the count is greater than 0, the script is set to do an additional analysis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is when the count is greater then 0 - the script does what it is suppose to.&lt;/P&gt;&lt;P&gt;When the count is equal to zero the script runs without any error messages, however, fails to give me the output message that it is programmed to. Can anyone tell me why?&lt;/P&gt;&lt;P&gt;I thought it may have been the order in which I programmed the evaluation, but I got the same results either way. I left both&lt;/P&gt;&lt;P&gt;sets in the code, with one commented out so you can see what I've tried with the same results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm in ArcGIS 10.3.1 and using Python 2.7.8&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the feedback.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Count number of records selected
count = arcpy.GetCount_management(ViewTable)
print str(count) +" issues were logged\n"

if count &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sc1 = arcpy.SearchCursor(ViewTable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; del sc1

else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("No Issues were logged during this walk through.\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No Issues were logged during this walk through."
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
##if count == 0:
##&amp;nbsp;&amp;nbsp;&amp;nbsp; #infile.write("No Issues were logged during this walk through.\n")
##&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No Issues were logged during this walk through."

##else:
##&amp;nbsp;&amp;nbsp;&amp;nbsp; sc1 = arcpy.SearchCursor(ViewTable)
##&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc1:
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
##&amp;nbsp;&amp;nbsp;&amp;nbsp; del sc1


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 07:43:03 GMT</pubDate>
    <dc:creator>RachelAlbritton</dc:creator>
    <dc:date>2021-12-12T07:43:03Z</dc:date>
    <item>
      <title>Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745391#M57620</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This should be pretty basic, but for the life of me I can not figure out why this conditional statement doesn't function correctly.&lt;/P&gt;&lt;P&gt;I'm using the count tool to count the # of selected records. If the count = 0, then the user should just get a message that says "No Issues were logged during this walk through." but if the count is greater than 0, the script is set to do an additional analysis.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My issue is when the count is greater then 0 - the script does what it is suppose to.&lt;/P&gt;&lt;P&gt;When the count is equal to zero the script runs without any error messages, however, fails to give me the output message that it is programmed to. Can anyone tell me why?&lt;/P&gt;&lt;P&gt;I thought it may have been the order in which I programmed the evaluation, but I got the same results either way. I left both&lt;/P&gt;&lt;P&gt;sets in the code, with one commented out so you can see what I've tried with the same results.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm in ArcGIS 10.3.1 and using Python 2.7.8&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the feedback.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Count number of records selected
count = arcpy.GetCount_management(ViewTable)
print str(count) +" issues were logged\n"

if count &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; sc1 = arcpy.SearchCursor(ViewTable)
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
&amp;nbsp;&amp;nbsp;&amp;nbsp; del sc1

else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("No Issues were logged during this walk through.\n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No Issues were logged during this walk through."
&amp;nbsp;&amp;nbsp;&amp;nbsp; 
##if count == 0:
##&amp;nbsp;&amp;nbsp;&amp;nbsp; #infile.write("No Issues were logged during this walk through.\n")
##&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No Issues were logged during this walk through."

##else:
##&amp;nbsp;&amp;nbsp;&amp;nbsp; sc1 = arcpy.SearchCursor(ViewTable)
##&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in sc1:
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
##&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; del row
##&amp;nbsp;&amp;nbsp;&amp;nbsp; del sc1


&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:43:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745391#M57620</guid>
      <dc:creator>RachelAlbritton</dc:creator>
      <dc:date>2021-12-12T07:43:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745392#M57621</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just as a quick test, I'd comment out the infile.write just to see if the print statement is invoked in the else part of the condition.&amp;nbsp; If that's the case, the problem isn't with your conditional statement, it's with that .write line.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Feb 2016 17:02:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745392#M57621</guid>
      <dc:creator>JamesCrandall</dc:creator>
      <dc:date>2016-02-12T17:02:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745393#M57622</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks James - I should have stated that I have tried that, and it still gave me the same scenario. I also stripped the entire analysis out of the if/else statement so that :&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if count == 0:&lt;/P&gt;&lt;P&gt;print somthing&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;else:&lt;/P&gt;&lt;P&gt;print something else&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When I do this, and count is equal to 0, it prints the message for the else statement. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Feb 2016 17:05:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745393#M57622</guid>
      <dc:creator>RachelAlbritton</dc:creator>
      <dc:date>2016-02-12T17:05:35Z</dc:date>
    </item>
    <item>
      <title>Re: Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745394#M57623</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think the problem is that arcpy.GetCount_management(ViewTable) returns an object.&lt;/P&gt;&lt;P&gt;So count will never equal 0.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You can test this by doing...&lt;/P&gt;&lt;P&gt;count = arcpy.GetCount_management(ViewTable)&amp;nbsp; &lt;/P&gt;&lt;P&gt;print type(count)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To get the integer value of the count object do this...&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;result&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;arcpy&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;GetCount_management&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;ViewTable&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="n"&gt;count&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="nb"&gt;int&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;result&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;getOutput&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;0&lt;/SPAN&gt;&lt;SPAN class="p"&gt;))&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Feb 2016 17:44:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745394#M57623</guid>
      <dc:creator>Kathleen_Crombez</dc:creator>
      <dc:date>2016-02-12T17:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745395#M57624</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks Kathleen! That's exactly what the issue was.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 12 Feb 2016 17:53:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/745395#M57624</guid>
      <dc:creator>RachelAlbritton</dc:creator>
      <dc:date>2016-02-12T17:53:40Z</dc:date>
    </item>
    <item>
      <title>Re: Python Conditional Statement not Working</title>
      <link>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/1007567#M59220</link>
      <description>&lt;P&gt;In ArcGIS Server 10.7.1, if you compare the object ("if result &amp;gt; 0") then sometimes, the boolean condition will return True and sometimes it returns False. Hope this helps anyone else wondering why their script breaks once every few hours.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Dec 2020 23:22:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-conditional-statement-not-working/m-p/1007567#M59220</guid>
      <dc:creator>ZianChoy</dc:creator>
      <dc:date>2020-12-07T23:22:32Z</dc:date>
    </item>
  </channel>
</rss>

