0

I need to access the dbf file to extract variable list (i.e. "CODE"). Basically I am calling dbf file to allMamrows variable and then I am appending using for loop. On running the script I am getting the following error. The dbf file is at right location, but still I am getting a error that file that does not exist. Please let me know what's wrong with the search cursor function in the script.

Traceback (most recent call last):
 File "C:\Users\Mukhtar_Ahmed\Desktop\Assignment_8\Python\MambalHab_Iterations.py", line 29, in <module>
 allMamRows = arcpy.SearchCursor ("Desktop\\Assignment_8\\GAPanalysisData\\Flmammal.dbf")
 File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\__init__.py", line 1179, in SearchCursor
 return gp.searchCursor(dataset, where_clause, spatial_reference, fields, sort_fields)
 File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\geoprocessing\_base.py", line 359, in searchCursor
 self._gp.SearchCursor(*gp_fixargs(args, True)))
IOError: "Desktop\Assignment_8\GAPanalysisData\Flmammal.dbf" does not exist.

Script

# Reading data from mammals list access file
allMamRows = arcpy.SearchCursor ("Desktop\\Assignment_8\\GAPanalysisData\\Flmammal.dbf")
# loop through mammals table and loading the codes into the list
mamList = []
i=0
for row in allMamRows:
 mamList.append(row.getValue("CODE"))
 print mamList[i]
 i = i +1
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 22, 2015 at 5:24
1
  • 3
    You file path is wrong. You will need to fix that before it will work. Commented Apr 22, 2015 at 6:21

1 Answer 1

1

This is really a programming question rather than a GIS one but two things spring to mind. The main issue is your path. On Windows I don't think Python will find any path in the form "Desktop\etc\etc". Unlike unix, you must specify a drive and there can also be many desktops (one for each account plus a global one). They are all usually found in a standard install in a path starting "C:\Users\". The 'global'one is usually "C:\Users\Default\". On this note it is bad practice to just dump everything onto the desktop. It is far better to put the file somewhere specific

The second thing is your file itself. While you can read a DBF file in the way you show, if this is part of a shapefile, it may be better to specify the path to the SHP file instead (arcpy will read the attributes in the dbf just the same) because if you start mucking about with the DBF in isolation of the SHP you can break your shapefile (especially if you delete rows or perform inserts).

answered Apr 22, 2015 at 6:22

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.