Select to view content in your preferred language

Problem with import table

2142
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
T__WayneWhitley
Honored Contributor
...notice that from your split function (that returns a list), you are fetching the 1st member [0], so you are not encountering the special character that would be on your 2nd member.

Note:  When I neglected to strip the character from the 'source' param (the 1st param in TableToTable), it throws 'cannot find table'.
When I fixed that, but forgot to do it for the 3rd param, the table name, it found the table, just could not complete the execution.

EDIT: How many lines do you have in your text file?....and what do you get when you print tables.readlines()?  I got (after opening the txt, pressing Enter (for a final return), and saving/closing file):

['Table_A\n', 'Table_B\n']

But I think you are onto something there - I didn't bother to include the file extension, not one for a file gdb... I was able to duplicate the 'The table was not found.  [Table_A]' error with (which was successfully fixed via stripping the special character):

>>> w = open(Tables, 'r')
>>> for table in w.readlines():
               full = os.path.join(source, table)
               if arcpy.Exists(full):
                              print 'True'
                              arcpy.TableToTable_conversion(full, r'C:\Data\base.gdb', table)
                              print 'success converting: ' + table
               else:
                              print 'False'

True
 
Traceback (most recent call last):
  File "<pyshell#44>", line 5, in <module>
    arcpy.TableToTable_conversion(full, r'C:\Data\base.gdb', table)
  File "C:\Program Files\ArcGIS\Desktop10.0\arcpy\arcpy\conversion.py", line 1463, in TableToTable
    raise e
ExecuteError: ERROR 999999: Error executing function.
The table was not found.
The table was not found. [Table_A]
Failed to execute (TableToTable).
0 Kudos
by Anonymous User
Not applicable
...notice that from your split function (that returns a list), you are fetching the 1st member [0], so you are not encountering the special character that would be on your 2nd member.

Note:  When I neglected to strip the character from the 'source' param (the 1st param in TableToTable), it throws 'cannot find table'.
When I fixed that, but forgot to do it for the 3rd param, the table name, it found the table, just could not complete the execution.

EDIT: How many lines do you have in your text file?....and what do you get when you print tables.readlines()?  I got (after opening the txt, pressing Enter (for a final return), and saving/closing file):

['Table_A\n', 'Table_B\n']

But I think you are onto something there - I didn't bother to include the file extension.


Ahh, I see.  It does indeed give me a list with the new line '\n'.  And that would explain why my initial results would print a new line before printing 'True'.  However, it is strange to me that when I checked for the existence of the table, it returned true, apparently ignoring the '\n' at the end.  I wonder why that is?

Here is what I get when I print the readlines(), so it appears you are correct.

['cama.dbf\n', 'cama_addresses.dbf\n', 'Duplicates.dbf']

Now I am curious as to why arcpy says these files exist.  This is strange, but now more than ever I would like to emphasize to KPG that this whole process is unnecessary to begin with since the ListTables() would be a much better alternative.  That way, you do not need to worry about strange things like that.
0 Kudos
T__WayneWhitley
Honored Contributor
True... obviously, yes, it isn't a good idea for one method to ignore what trips another up, as in Exists reporting 'True'.  It could be the internal programming provides a 'trim' function for this, whereas the TableToTable was not at all expecting this.

Regardless, in this case, you are right that it is irrelevant and a little bit foolish to want to do it this way rather than reading it directly UNLESS for some reason it is desired to 'create' the input params for TableToTable for bulk processing later without creating a 'staging' gdb.  Maybe that was just the preference....at any rate, chalk it up to an 'academic' lesson.  Trust me, this minute detail may be needed later.  ...think KBG at least deserves a point for throwing us a curve ball!  It has been handled, maybe not out of the park, but you know, on base somewhere....
0 Kudos
by Anonymous User
Not applicable
True, I do believe that is an important detail to know.  I did not know that when parsing through a text document it would read the '\n' for whenever it moves to a new line as shown in the list:

['cama.dbf\n', 'cama_addresses.dbf\n', 'Duplicates.dbf']

Good to know!
0 Kudos