# Joining feature classes defined in list to dbf tables which defined in another list using ArcPy?

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
#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

• 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 Jul 24 '19 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 Jul 29 '19 at 17:59
• 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 Jul 29 '19 at 18:04
• Nice! Accept and upvote my answer below – BERA Jul 29 '19 at 18:06

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