...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.
>>> 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).
import arcpy from os import path as p arcpy.env.workspace = source = r'G:\PROJECTS\Cedar\Address\Tables' gdb = p.join(source,'Test_db.gdb') tables = open(r'C:\Documents and Settings\gis\Desktop\Tables.txt', 'r') for table in tables.readlines(): full = p.join(source, table) print full if arcpy.Exists(full): print 'True' arcpy.TableToTable_conversion(full, gdb, table.split('.')[0]) # removes '.dbf' print 'Converted %s to %s' %(table,gdb) else: print 'False'
>>> # Tables is my ref to the txt... >>> w = open(Tables, 'r') >>> for table in w.readlines(): # if I apply the text 'slicing' in the path join part of the process, # no change is applied where it is also needed for the 'table' var param in TableToTable: full = os.path.join(source, table[0:-1]) 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#48>", 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. Failed to execute (TableToTable). >>> # So what just happened?? >>> # This time the table was found, but the conversion could not be completed...same generic error code. >>> # But if you refresh Catalog, you'll see a strange entry, Table_A with a 'special character' appended. >>> # This is how the character is interpreted within ArcGIS...notice that the source table was found above...'True' returned. >>> # BUT, processing halted. >>> # Try again, this time intervening to redefine the 'table' variable for both the input table source and the output name: >>> # (The conversion is completed. See the attached illustration that includes the Table_A incomplete table execution.) >>> w.close() >>> w = open(Tables, 'r') >>> for table in w.readlines(): table = table[0:-1] print "table: " + "'" + table + "'" full = os.path.join(source, table) print 'full pathname: ' + "'" + full + "'" if arcpy.Exists(full): print 'True - table exists: ' + full arcpy.TableToTable_conversion(full, r'C:\Data\base.gdb', table) print 'success converting: ' + table else: print 'False' table: 'Table_A' full pathname: 'C:\Data\Data.gdb\Table_A' True - table exists: C:\Data\Data.gdb\Table_A <Result 'C:\\Data\\base.gdb\\Table_A'> success converting: Table_A table: 'Table_B' full pathname: 'C:\Data\Data.gdb\Table_B' True - table exists: C:\Data\Data.gdb\Table_B <Result 'C:\\Data\\base.gdb\\Table_B'> success converting: Table_B >>>
for line in lines: line = line[0:-1] print line # feed this into the path join, etc.
import arcpy from os import path as p arcpy.env.workspace = source = r'G:\PROJECTS\Cedar\Address\Tables' tables = open(r'C:\Documents and Settings\gis\Desktop\Tables.txt', 'r') for table in tables.readlines(): full = p.join(source, table) print full if arcpy.Exists(full): print 'True' else: print 'False'
if arcpy.Exists(line): print 'all is well' # proceed with processing else: print 'uh-oh, better check this: ' + line # could even raise an exception here, if you wanted
for table in ['Table_A', 'Table_B']:
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 .
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)
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)
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)
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.
サインインしたメンバーは投稿、更新のフォローなどができます。初めてですか?無料アカウントを登録してください。
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.