I'm learning ArcPy and do not understand why it says this file path does not exist...What am I doing wrong. In the end I'd like to accomplish code similar to this:
import arcpy # Open a searchcursor # Input: C:/Data/Counties.shp # Fields: NAME; STATE_NAME; POP2000 # Sort fields: STATE_NAME A; POP2000 D rows = arcpy.SearchCursor("c:/data/counties.shp", fields="NAME; STATE_NAME; POP2000", sort_fields="STATE_NAME A; POP2000 D") # Iterate through the rows in the cursor and print out the # state name, county and population of each. for row in rows: print("State: {0}, County: {1}, Population: {2}".format( row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")))
- A MORE CLEAN VERSION CAN BE SEEN OVER THIS LINK: SearchCursor—Help | ArcGIS Desktop
I attached a screen shot of my issues.
You may want to move your post to a more appropriate space like python snippets Python ArcGIS Pro for a broader audience
You need to use raw-string literals or properly escape your path strings. Instead of:
'C:\arcgis\ArcTutor\Geocoding\Atlanta.gdb'
use:
r'C:\arcgis\ArcTutor\Geocoding\Atlanta.gdb'
A couple things to consider: when posting up Python code here on the Geonet, use the Syntax Highlighter so we can read the code. See /blogs/dan_patterson/2016/08/14/script-formatting
Also, don't use the old style Search Cursor; instead use the Data Access Search Cursor. Check out the entire Data Access Module.
This is what the code you provided above looks like when you properly format it with the Syntax Highlighter:
import arcpy
# Open a searchcursor
# Input: C:/Data/Counties.shp
# Fields: NAME; STATE_NAME; POP2000
# Sort fields: STATE_NAME A; POP2000 D
rows = arcpy.SearchCursor("c:/data/counties.shp",
fields="NAME; STATE_NAME; POP2000",
sort_fields="STATE_NAME A; POP2000 D")
# Iterate through the rows in the cursor and print out the
# state name, county and population of each.
for row in rows:
print("State: {0}, County: {1}, Population: {2}".format(
row.getValue("STATE_NAME"),
row.getValue("NAME"),
row.getValue("POP2000")))
I think you'll agree it's a whole lot easier to read.