nasrinebi

Hi, I have a problem regarding python script. I worte an script to convert dbf to csv

Discussion created by nasrinebi on Jun 7, 2014
Latest reply on Jun 9, 2014 by iamurray
Hi, I have a problem regarding python script. I wrote an script to convert dbf to csv. I use a model builder to create a dbf file and by using that python script I want to get csv format of the output. However I don't know how to set input and out parameters in python to use it in model builder.
Here is my code also:
import csv,arcgisscripting
from dbfpy import dbf
gp = arcgisscripting.create()

try:
    inFile = gp.GetParameterAsText(0) #Input
    outFile = gp.GetParameterAsText(1)#Output
    dbfFile = dbf.Dbf(open(inFile,'r'))
    csvFile = csv.writer(open(outFile, 'wb'))
   
    headers = range(len(dbfFile.fieldNames))
   
    allRows = []
    for row in dbfFile:
        rows = []
        for num in headers:
            rows.append(row[num])
        allRows.append(rows)
         
    csvFile.writerow(dbfFile.fieldNames)
    for row in allRows:
        print row
        csvFile.writerow(row)
       
except:
    print gp.getmessage()

Outcomes