Select to view content in your preferred language

Create file GDB, importing tables results in empty list when using arcpy.ListTables()

3087
4
Jump to solution
07-31-2012 06:22 AM
RickardHansen
Occasional Contributor
I'm creating a file GDB and then importing tables (Excel) with TableToGeodatabase. After that I want to list them using arcpy.ListTables but it results in an empty list, even though they are there when I check in ArcCatalouge. In ArcCatalouge I can copy the tables for example but in the Python window I can't list them or access them (like they don't exist).

However, if I create a file geodatabase in ArcCatalouge and then import the tables using right click > import (table, multiple) the tables will show up in Python using arcpy.ListTables()

import arcpy  # Get parameters to create geodatabase OutputFolder = arcpy.GetParameterAsText(0) FGDName = arcpy.GetParameterAsText(1)  # Create File GDB... OutputGDB = OutputFolder + '\\' + FGDName + '.gdb' arcpy.management.CreateFileGDB(OutputFolder, FGDName)  # Set current workspace to to file geodatabase arcpy.env.workspace = OutputFolder  # Get parameters to import tables to geodatabase adress = arcpy.GetParameterAsText(2) adress_xy = arcpy.GetParameterAsText(3)  # Import tables to geodatabase arcpy.conversion.TableToGeodatabase([adress, adress_xy], OutputGDB)


Any help would be greatly appreciated-
Thanks
/ Rickard
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChrisSnyder
Honored Contributor
Never had much consistent luck with using .xls files as an "ESRI-friendly" format... In my experience, it's best to use .dbf, .txt, .csv, etc. if you can.

However, in v10.1 it seems to work for me (the .xls file is considered a workspace):

>>> import arcpy >>> arcpy.env.workspace = r"C:\Temp\logist_reg_merge_20120725_runs.xls" >>> tblList = arcpy.ListTables() >>> print tblList [u'PivotReport$', u'RawData$', u'Sheet1$', u'Sheet2$']

View solution in original post

0 Kudos
4 Replies
ChrisSnyder
Honored Contributor
Try using this tool: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/RefreshCatalog/000v0000004z000000/

to give ArcGIS a kick in the ... before you make the table list.
0 Kudos
RickardHansen
Occasional Contributor
It didn't work to kick ArcGIS in the... However, I found a solution (sort of).
When I use arcpy.ListTables() in the Python interpreter in ArcCataloge it won't list any tables in excel format but will list tables in dbf format. However, my intention was to use it in a script tool and there arcpy.ListTables works just fine with excel format. I'm not sure but I think it has something to do with formatting pathways. In my script to I use arpy.GetParameterAsText and that works fine.
0 Kudos
ChrisSnyder
Honored Contributor
Never had much consistent luck with using .xls files as an "ESRI-friendly" format... In my experience, it's best to use .dbf, .txt, .csv, etc. if you can.

However, in v10.1 it seems to work for me (the .xls file is considered a workspace):

>>> import arcpy >>> arcpy.env.workspace = r"C:\Temp\logist_reg_merge_20120725_runs.xls" >>> tblList = arcpy.ListTables() >>> print tblList [u'PivotReport$', u'RawData$', u'Sheet1$', u'Sheet2$']
0 Kudos
RickardHansen
Occasional Contributor
I just figured it out with your help, thanks! When I use GetParameterAsText I actually point out the table in the Excel file, not the Excel file itself, which is exactly what you're doing when setting the Excel file as a workspace. I tried and tried listing the Excel file (not the table within) while having the folder as a workspace. That kinda make sense now.
0 Kudos