I am bastardizing Matt Perry's text2shp.py and running into an error.&nbsp; <br><br>I am taking values from a text file and building a shapefile.&nbsp; The error occurs when I try to set the value of first field of a feature.&nbsp; I am not sure what would cause this error.&nbsp; 
<br><br>Below is the shell output.&nbsp; The first list printed is the column names, the second list is the field types.  The last line before the error is the column number and the value to be inserted into that field (print colNum, cols[colNum]).&nbsp; 
<br><br>D:\datascripts&gt;python csv2shp.py<br><br>['stn_type', 'stn_name', 'X', 'Y', 'col_meth', 'col_date', 'org_name', 'org_type<br>', 'gnd_elev', 'uniq_id', 'tos_elev', 'bos_elev', 'comments']<br><br>[4, 4, 2, 2, 4, 4, 4, 4, 4, 4, 4, 4, 4] 
<br><br>0 Monitoring Well<br><br>Traceback (most recent call last):<br>&nbsp; File &quot;csv2shp.py&quot;, line 129, in ?<br>&nbsp;&nbsp;&nbsp; f.setField(colNum, cols[colNum])<br>&nbsp; File &quot;C:\PROGRA~1\FWTOOL~1.5\pymod\ogr.py&quot;, line 755, in __getattr__
<br>&nbsp;&nbsp;&nbsp; raise AttributeError, name<br>AttributeError: setField<br><br>__________________________________________-<br>here is the relevant part of the script <br>__________________________________________<br><br>ds = driver.CreateDataSource
(outputFile)<br>layer = ds.CreateLayer(outputFile, geom_type=ogr.wkbPoint)<br><br>print colNames<br>print colTypes<br>#create fields<br>for j in range(len(colNames)):<br>&nbsp;&nbsp;&nbsp; fd = ogr.FieldDefn(colNames[j].strip(), colTypes[j])
<br>&nbsp;&nbsp;&nbsp; fd.SetWidth(maxWidth[j] + 12)<br>&nbsp;&nbsp;&nbsp; fd.SetPrecision(precision[j]+1)<br>&nbsp;&nbsp;&nbsp; layer.CreateField(fd)<br><br>#second pass through data file<br>myFile = open(inputFile, 'r')<br><br>#skip the header row<br>line = myFile.readline
()<br>#read the first data row&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>line = myFile.readline()<br><br>while line:<br>&nbsp;&nbsp;&nbsp; cleanline = line.replace('\n','')<br>&nbsp;&nbsp;&nbsp; cols = cleanline.split(delimiter)<br><br>&nbsp;&nbsp;&nbsp; #create the feature<br>&nbsp;&nbsp;&nbsp; f= ogr.Feature
(feature_def=layer.GetLayerDefn())<br><br>&nbsp;&nbsp;&nbsp; # Fill in the attribute fields<br>&nbsp;&nbsp;&nbsp; for colNum in range(len(cols)):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; print colNum, cols[colNum]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.setField(colNum, cols[colNum])&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # this is line 129 where the error is being raised
<br><br>&nbsp;&nbsp;&nbsp; # if there is a coordinate, use it to create a geometry<br>&nbsp;&nbsp;&nbsp; if cols[xColNum] and cols[yColNum]:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x = float(cols[xColNum])<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; y = float(cols[yColNum])<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #create point feature<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; wkt = 'POINT(%f %f)' % (x,y)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; g = ogr.CreateGeometryFromWkt(wkt)<br><br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; f.SetGeometryDirectly(g)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; layer.CreateFeature(f)<br>&nbsp;&nbsp;&nbsp; f.Destroy()<br><br>#destroying the data source closes the output shapefile
<br>ds.Destroy()<br>