Quantcast
Channel: Question and Answer » arcpy
Viewing all articles
Browse latest Browse all 767

Python says my shapefile does not exist. Why?

$
0
0

I’m working on a script that prints the names of hospitals that are within a certain zip-code. When I run my code, though, python keeps giving me an Error message that says that my Hospitals shapefile does not exist. I’ve tested to see whether or not the shapefile exists using arcpy.Exists and I get the answer “True”. I was also wondering if it might be because the file is locked in some way but I’ve tried deleting my objects and cursors as well as closing arcgis and restarting python and nothing has changed.

Can anyone tell me why Python is not recognizing my shape file? Thank you!

Code for reference:

import arcpy
arcpy.env.workspace=r"C:UsersCaraDocumentsMPSGISProgramming and ScriptingLab6Lab 6 Data"
work=arcpy.env.workspace
zip5=78705
strZip=str(zip5)
arcpy.env.overwriteOutput = True

def searchHospitals(work,zip5):

    fc= "Hospitals.shp"
    #create a list to store values
    hospitals=[]

    whereClause= '"ZIPCODE" LIKE'+"'%s%%'"% strZip 
    sCursor= arcpy.SearchCursor(fc, whereClause, "", "", "")

    for row in sCursor:
        rowHospital = row.getValue("NAME")

        #if rowHospital value is not already in hospitals, append.
        if (not(rowHospital in hospitals)):
            hospitals.append(rowHospital)

        #number of hospitals in list
        count= len(hospitals)

        #print results
        print hospitals
        print "Total %s hospitals were found in zip-code %s"%(count, zip5)

    del row, sCursor

Here is the error message:

searchHospitals(work,zip5)

   Traceback (most recent call last):
  File "<pyshell#4>", line 1, in <module>
    searchHospitals(work,zip5)
  File "C:UsersCaraDocumentsMPSGISProgramming and ScriptingPython Scriptscursor_objects.py.py", line 98, in searchHospitals
    sCursor= arcpy.SearchCursor(fc, whereClause, "", "", "")
  File "C:Program Files (x86)ArcGISDesktop10.2arcpyarcpy__init__.py", line 1167, in SearchCursor
    return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)
  File "C:Program Files (x86)ArcGISDesktop10.2arcpyarcpygeoprocessing_base.py", line 359, in searchCursor
    self._gp.SearchCursor(*gp_fixargs(args, True)))
IOError: "Hospitals.shp" does not exist

Viewing all articles
Browse latest Browse all 767

Trending Articles