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")))
Solved! Go to Solution.
arcpy.AddMessage("State: {0}, County: {1}, Population: {2}".format(row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")))
theMessage = "State: {0}, County: {1}, Population: {2}".format(row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")) arcpy.AddMessage(theMessage)
import arcpy LID = arcpy.GetParameterAsText(0) rows = arcpy.SearchCursor("C:/Python/Python.gdb/Counties", "LINE_ID = 'LID'") for row in rows: row.getValue(rows) theMessage = "State: {0}, Name: {1} , Population: {2}".format( row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")) arcpy.AddMessage(theMessage) del rows, LID
I took your advice and got it to work like this:import arcpy LID = arcpy.GetParameterAsText(0) rows = arcpy.SearchCursor("C:/Python/Python.gdb/Counties", "LINE_ID = 'LID'") for row in rows: row.getValue(rows) theMessage = "State: {0}, Name: {1} , Population: {2}".format( row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")) arcpy.AddMessage(theMessage) del rows, LID
I needed to define "theMessage" without indentation and add row.getValue(rows) instead under "for row in rows".
THANK YOU!!!!!!!!!!
import arcpy LID = arcpy.GetParameterAsText(0) rows = arcpy.SearchCursor("C:/Python/Python.gdb/Counties", "LINE_ID = 'LID'") for row in rows: theMessage = "State: {0}, Name: {1} , Population: {2}".format(row.getValue("STATE_NAME"), row.getValue("NAME"), row.getValue("POP2000")) arcpy.AddMessage(theMessage) del rows, LID
for row in rows:
theMessage = "State: {0}, Name: {1}, Population: {2}".\
format(row.getValue("STATE_NAME"), \
row.getValue("NAME"), \
row.getValue("POP2000"))
arcpy.AddMessage(theMessage)
import arcpy LID = arcpy.GetParameterAsText(0) rows = arcpy.SearchCursor("C:/Python/Python.gdb/Counties", "LINE_ID = 'LID'") for row in rows: theMessage = "State: {0}, Name: {1} , Population: {2}".format(row.getValue("STATE_NAME"), row.getValue("NAME"),row.getValue("POP2000")) arcpy.AddMessage(theMessage) del rows, LID
I edited my response above because I was having trouble formatting my message...
Do you have a script tool? Are you running the code from the toolbox? Try editing the script tool py you are using, pasting in the portion from above...again, if there's a problem, I need to know what the error messages are.
Of course if not running from ArcToolbox, then of course you won't see the messages.
Hope that helps.
Wayne