AnsweredAssumed Answered

ListFields returning blanklist

Question asked by jollygood4418 on Jul 26, 2016
Latest reply on Jul 27, 2016 by xander_bakker

Hi Everyone, I am trying to convert dbf to csv using the following code:


import arcpy
import os
import csv

def DBFtoCSV(path):
    '''Convert every DBF table into CSV table.
    arcpy.env.workspace = path
    tablelist=arcpy.ListTables('*', 'dBASE')
    for table in tablelist:
        outputFile = '{}.csv'.format(table.split('.dbf')[0])
        # Get the fields in the dbf to use for the cursor and csv header row.
        fields = []
        for field in arcpy.ListFields(table):

# Make the csv.
        with open((os.path.join(path,outputFile)),'wb') as output:
            dataWriter = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL)

    # Write header row.

    # Write each row of data to the csv.
            with arcpy.da.SearchCursor(table, fields) as cursor:
                for row in cursor:

        print('Finished creating {}'.format(outputFile))

if __name__ == '__main__': 

I am getting an error at the SearchCursor because it says field names must be string or non empty. I added the print statement and it turns out my list of fields is empty. Can anyone tell me why this is?