I was wondering if i could ask for some advise. I wrote a script for my workplace that imports CSV data from a template sheet (with data) to a DB table. I wrote it with a series of loops so that I wouldn't have to hardcode the headers names(43 header name). The template is used so that the headers do match exactly the table in the DB. I keep getting a run time error at the line execution the row.name, where name is a variable that varies in value as the loop iterates thought each header name. When I run it through the degugger the explicit name does not exist. Is there an alternate way of doing this so that I dont have to hardcode this into the code?
Thank you ,
Iris
Thank you ,
Iris
Code:
import arcgisscripting
gp = arcgisscripting.create(9.3)
gp.toolbox = "management"
# Define workspace for infile and data out put
workspace =gp.GetParameterAsText(0)#define workspace
inFile ='gp.GetParameterAsText(1)# shape out file
dataOutPut =gp.GetParameterAsText(2)#in geochem file
gp.workspace = workspace
# open file and read header line.
openInFile = open(inFile)
headerLine = openInFile.readline()
#splits header line by comma
valueList = headerLine.split(",")
#iterating through the headerlist and create a header list
index = 0
for value in valueList:
#index header names
header = valueList[index]
#while values in the value list iterate through list
while index <= valueList.index(header):
#read the rest of the data
cValuesList = openInFile.readlines()
#for data in the data list
for cValue in cValuesList:
#split the datalist by comma
gValue = cValue.split(",")
#iteralete throught the datalist
headerindex = 0
#create an insert cursor
rows = gp.insertCursor(dataOutPut)
#for each data value in the datalist, create a new row
for gcvalue in gValue :
row = rows.NewRow()
Name = str(valueList[headerindex])
row.Name = gValue[headerindex] #( line 46, in <module>
#RuntimeError: ERROR 99999: Error executing function.
rows.InsertRow(row)
headerindex += 1
#add 1 to the counter
index += 1
# Clean up the cursor
#del rowInserter
gp.getmessages()
Comment