AnsweredAssumed Answered

Python Conditional Statement not Working

Question asked by rralbritton on Feb 12, 2016
Latest reply on Feb 12, 2016 by rralbritton

This should be pretty basic, but for the life of me I can not figure out why this conditional statement doesn't function correctly.

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.

 

My issue is when the count is greater then 0 - the script does what it is suppose to.

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?

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

sets in the code, with one commented out so you can see what I've tried with the same results.

 

I'm in ArcGIS 10.3.1 and using Python 2.7.8

 

Thanks for the feedback.

 

#Count number of records selected
count = arcpy.GetCount_management(ViewTable)
print str(count) +" issues were logged\n"

if count > 0:
    sc1 = arcpy.SearchCursor(ViewTable)
    for row in sc1:
        infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
        print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
        del row
    del sc1

else:
    
    infile.write("No Issues were logged during this walk through.\n")
    print "No Issues were logged during this walk through."
    
##if count == 0:
##    #infile.write("No Issues were logged during this walk through.\n")
##    print "No Issues were logged during this walk through."

##else:
##    sc1 = arcpy.SearchCursor(ViewTable)
##    for row in sc1:
##        infile.write("Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n")
##        print "Stop "+str(row.Stop_Num)+": "+(row.Issue)+"\n\n"
##        del row
##    del sc1



Outcomes