2

I am trying to write a script where the user can search for a five digit zipcode using an input statement and a search cursor. The zipcodes in the file though are nine characters long (i.e. xxxxx-xxxx) so I'm trying to use the wildcard character after five digits in the where clause but I can't figure out either where to put it or the syntax I'm supposed to use. Currently I can get the use input zipcode to print out but when I try putting the % wildcard in I get an error. Can anyone help me?

Here is my code so far:

import arcpy
#set workspace
work=raw_input("work= ")
arcpy.env.workspace=work
zip5=input("zip5= ")
strZip= str(zip5)
def searchHospitals(work,zip5):
 fc= "Hospital.shp"
 whereClause= '"ZIPCODE" LIKE'+"'%s'"% strZip
 print whereClause
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jul 25, 2015 at 15:34

1 Answer 1

7

I would use format instead, since % is probably your wildcard character.

def searchHospitals(work,strZip):
 fc= "Hospital.shp"
 whereClause= '"ZIPCODE" LIKE'+"'{0}%'".format(strZip)

But you can also use double percent signs (%%) in your method:

def searchHospitals(work,strZip):
 fc= "Hospital.shp"
 whereClause= '"ZIPCODE" LIKE'+"'%s%%'"% strZip 
answered Jul 25, 2015 at 16:32

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.