Simple looping using list of CSV values in Python

Discussion created by utz.ryan on Feb 9, 2012
Latest reply on Feb 9, 2012 by utz.ryan

I'm valiantly attempting to teach myself Python scripting, and not enjoying this very much so far... All I am trying to do is import a list file (.csv) that corresponds to a field in a shapefile and batch-process some basic GIS functions in a loop. I cannot figure out how to call up the .csv entry in a list for use in an arcpy command. Forgive me if this is a very basic problem, but I've scoured the web for hours trying to figure this out and am getting nowhere fast.

When one is for-looping with arcpy commands, how in the world do you get Python to accept the value in the loop?? Below I can successfully import the .csv list, get one arcpy command (MakeFeatureLayer_management) to go, but then when I want to insert the first value from the .csv list (in the SelectLayerByAttribute_management command) , nothing I try satisfies Python. What am I doing wrong here?!?

Here's the code:

import csv, arcpy
sheds = csv.reader(open('E:/Weathering_GIS/Sheds.csv','rb'))

from arcpy import env
from arcpy.sa import *

env.workspace = 'E:/Weathering_GIS/Working.gdb'

for row in sheds:
   print row
   arcpy.MakeFeatureLayer_management('E:/Weathering_GIS/Working.gdb/USGS_Points', 'Shedpoints9')
   arcpy.SelectLayerByAttribute_management("Shedpoints9", "NEW_SELECTION", "GageCode='"+row.insert)  #here's where it's breaking. How can I insert the first of the "sheds"?!?