Select to view content in your preferred language

Problem with import table

2072
23
12-18-2012 10:58 AM
_ukaszZaremba
Emerging Contributor
Hello,

I have a source geodatabase with three tables: Table_A, Table_B and Table_C.
I would like to export two of them to another geodatabase.
The list of tables I would like to export is written in txt files.

I've written a script in Python to do that but I have an error when I run it.


When the list contains only one table's name, the export is accomplished correctly.

Can You help mi with this script?

import arcpy

source="C:\\Data\\Data.gdb\\"
destination="C:\\Data\\Base.gdb"
Tables="C:\\Data\\Tables.txt"

w=open(Tables,'r')
lines=w.readlines()
for line in lines:
arcpy.TableToTable_conversion(source+line,destination,line)
w.close()


Error:
"arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
The table was not found.
The table was not found. [Table_A]
Failed to execute (TableToTable)."
Tags (2)
0 Kudos
23 Replies
GuidoStein
Deactivated User
table to table is not a line by line cursor for writing tables, you should be able to point directly to your tables and set the output destination and name.
0 Kudos
KevinBell
Deactivated User
...just a guess, but is it the // on the end of your source string?
0 Kudos
by Anonymous User
Not applicable
I have a source geodatabase with three tables: Table_A, Table_B and Table_C.
I would like to export two of them to another geodatabase.
The list of tables I would like to export is written in txt files.


It would be much easier to use the ListTables() function. 

import arcpy, os
from os import path as p

arcpy.env.workspace = source = r"C:\Data\Data.gdb"
destination= r"C:\Data\Base.gdb"

for table in arcpy.ListTables('Table_*'):    # IF tables really are named  like Table_A
    arcpy.TableToTable_conversion(p.join(source,table),destination,table)
    print 'Exported %s to %s'  %(table,destination)
0 Kudos
_ukaszZaremba
Emerging Contributor
Yes, there is. For one table in txt file it works.

The same script with import feature classes from one geodatabase to another (FeatureClassToGeodatabase_conversion), works correct.
0 Kudos
_ukaszZaremba
Emerging Contributor
It would be much easier to use the ListTables() function. 

import arcpy, os
from os import path as p

arcpy.env.workspace = source = r"C:\Data\Data.gdb"
destination= r"C:\Data\Base.gdb"

for table in arcpy.ListTables('Table_*'):    # IF tables really are named  like Table_A
    arcpy.TableToTable_conversion(p.join(source,table),destination,table)
    print 'Exported %s to %s'  %(table,destination)


OK, but I would like to import not all tables from source geodatabase (only Table_A and Table_B). I'm not interested in Table_C .

Thanks for help.
0 Kudos
by Anonymous User
Not applicable
OK, but I would like to import not all tables from source geodatabase (only Table_A and Table_B). I'm not interested in Table_C .


This can be done easily with an if test.  For example, "if table != 'Table_C:'"

This will exclude Table_C
import arcpy, os
from os import path as p

arcpy.env.workspace = source = r"C:\Data\Data.gdb"
destination= r"C:\Data\Base.gdb"

for table in arcpy.ListTables():  
    if table != 'Table_C': 
        arcpy.TableToTable_conversion(p.join(source,table),destination,table)
        print 'Exported %s to %s'  %(table,destination)
0 Kudos
T__WayneWhitley
Honored Contributor
for table in ['Table_A', 'Table_B']:

Replace that line in Caleb's code, will that work --- substituting one list for a more limited list.  Give Caleb credit, if you will.

EDIT:  Hello Caleb - you get at least a point on that 1st bit about ListTables, all in the same line with the string filter.  Just for the 'clean-appeal'.
0 Kudos
by Anonymous User
Not applicable
for table in ['Table_A', 'Table_B']:


Even better 🙂
0 Kudos
_ukaszZaremba
Emerging Contributor
Thank you for help.

I'm curious why my solution does not work? 🙂
Is it possible to use txt file?
0 Kudos