1

I am trying to join feature classes in a list to tables in another list using a join field which is the same for all joins. In general terms, I want to join the first feature class in the list to the first dbf table in the list, the second feature class to the second table, an so forth. Here are two codes I have written and I get error messages for both.

import arcpy
>>> arcpy.env.workspace= c:/Users/Administrator/Documents/ArcGIS/NewFileGeodatabase.gdb"
#Trial 1
>>> fclist2= arcpy.ListFeatureClasses("D*", "point", "")

>>> tablesmplg= arcpy.ListTables("", "")

>>> for table in tablesmplg:
...     for fc in fclist2:
...         arcpy.JoinField_management(table, "NEAR_FID", fc, "OBJECTID", "")
...     

Runtime error  Traceback (most recent call last):   File "<string>", line 3, in <module>   File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 6597, in JoinField     raise e ExecuteError: ERROR 000499: table is not editable Failed to execute (JoinField).  

Trial 2

>>> in_data= arcpy.ListTables("", "")

>>> in_field= "NEAR_FID"

>>> join_table= arcpy.ListFeatureClasses("D*", "point", "")

>>> join_field="OBJECTID"

>>> for table in in_data:
...     for fc in join_table:
...         arcpy.JoinField_management(in_data, in_field, join_table, join_field, "")
...         
Runtime error 
Traceback (most recent call last):
  File "<string>", line 3, in <module>
  File "c:\program files (x86)\arcgis\desktop10.5\arcpy\arcpy\management.py", line 6597, in JoinField
    raise e
RuntimeError: Object: Error in executing tool
4
  • Your for loops are incorrect, you do fc1-tbl1, fc1-tbl2 when you want fc1-tbl1, fc2-tbl2 etc. Try: for fc, table in zip(fclist2, tablesmplg): this will iterate over both lists at the same time
    – Bera
    Commented Jul 24, 2019 at 21:01
  • I modified as follows: for table, fc in zip(tablessmplg1, fclist): ... arcpy.JoinField_management(table, "NEAR_FID", fc, "OBJECTID", "") It worked ! Thank you !!!
    – ana.lmb
    Commented Jul 29, 2019 at 17:59
  • 1
    Hi BERA, I am a graduate student and new to this site. How do I give a 'thumbs-up', 'positive vote' or similar to acknowledge your comment sorted out my issue? Thanks.
    – ana.lmb
    Commented Jul 29, 2019 at 18:04
  • Nice! Accept and upvote my answer below
    – Bera
    Commented Jul 29, 2019 at 18:06

1 Answer 1

0

Your for loops are incorrect, you do fc1-tbl1, fc1-tbl2 when you want fc1-tbl1, fc2-tbl2 etc. Try: for fc, table in zip(fclist2, tablesmplg): this will iterate over both lists at the same time

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.