3

In my code below, how do I get the Desired Output?

# Get a list of all 'SITE_NFID' in the dashboard_site_summary table that don't have a match in the nfid_fqn_associations table
dashboard_site_summary_list = []
with arcpy.da.SearchCursor(dashboard_site_summary, ['SITE_NFID']) as cursor:
    for row in cursor:
        if row[0] not in nfa_dict:
            dashboard_site_summary_list.append(row[0]))

# Insert the NFID's into the SHP_Report that didn't have a NFA match to ensure ALL dashboard_site_summary NFID's are accounted
cursor = arcpy.da.InsertCursor(shp_report, ['SITE_NFID'])
for item in dashboard_site_summary_list:
    cursor.insertRow(item)

Current output in the "dashboard_site_summary_list":

Current Output = ['1903BRUF.65', '1903BRUF.65']<---Doesn't work
Desired Output = [(('1903BRUF.65'),),(('1903BRUF.65'),)] <----------Works

Article I found showing correct syntax: https://support.esri.com/en/technical-article/000011654

My best attempt to fix the output of the list:

# Get a list of all 'SITE_NFID' in the dashboard_site_summary table that don't have a match in the nfid_fqn_associations table
dashboard_site_summary_list = []
with arcpy.da.SearchCursor(dashboard_site_summary, ['SITE_NFID']) as cursor:
    for row in cursor:
        if row[0] not in nfa_dict:
            dashboard_site_summary_list.append('((' + str(row[0]) + ',),')
1
  • 2
    I cant test now but focus on cursor.insertRow(item) and keep your "current output". Try cursor.insertRow([item]) or cursor.insertRow((item,))
    – Bera
    Commented Mar 6, 2020 at 18:06

1 Answer 1

7

The input to insertRow() must be a list or tuple.

Instead of building this as a string value as listed above,

dashboard_site_summary_list.append('((' + str(row[0]) + ',),')

append a tuple:

dashboard_site_summary_list.append((row[0],))  # don't forget the comma; see below for type comparison

or list (whichever you prefer):

dashboard_site_summary_list.append([row[0]]) # doesn't matter whether you include the comma here

>>> test = ('15')
>>> type(test)
<class 'str'>
>>> test = ('15',)
>>> type(test)
<class 'tuple'>

Or, you can leave the output as it currently is, and just add the syntax for tuple or list on the insertRow() step.

cursor.insertRow((item,)) #don't forget the comma

or

cursor.insertRow([item])

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.