AnsweredAssumed Answered

User Input, SearchCursor, and for loop?

Question asked by sburnet9 on Nov 28, 2017
Latest reply on Dec 2, 2017 by xander_bakker

I'm working on a project in which I'm trying to utilize user input in order to search an attribute table for a city. If the city is not present in the table, I want to have a secondary response. So far, I've been using a searchCursor followed by a for loop and then an if statement. If I use a single If statement, I am able to achieve a single response. But if I include a second conditional statement, be it an elif an else or a second if, the script goes through the whole table and gives me a response for each row. Ideally, I would like it to give me a single response (ie. "Yes, its in the table", "No its not in the table"). I'm relatively new to arcGIS, and even newer to Python. Below is my sample text. Any help would be greatly appreciated.

#import necessary tools
import arcpy
from arcpy import env
import sys

#set workspace
arcpy.env.workspace = r'C:\Data' #generic source for data

#inquire user input
print "Please search for a city in New Mexico within 10 Miles of an Amtrak Station."
userInput = raw_input ("Which city would you like to check? ")

#establish the SearchCursor
citySearch = arcpy.da.SearchCursor('CitiesAmtrak.shp', 'NAME')

#create a loop to utilize SearchCursor and provide feedback
for column in citySearch:
    if userInput in column:
        print "This city is within 10 miles of an Amtrak Station."
    if userInput not in column:
        print "no"