Select to view content in your preferred language

using da.UpdateCursor's updateRow(row) I get "TypeError: value #1 - unsupported type: list

618
2
Jump to solution
07-07-2023 02:19 PM
twhammond
New Contributor II

Hello everyone,

I am running a python script I wrote from a geoprocessing toolbox.  Essentially, its purpose is to take data from an excel file and update specific rows in the feature class attribute table.  Most of the script works, but I tried to add some additional functionality to create a new field in the table and populate it, and this is the portion that broke.

The problem function is as follows:

## Funtion to create a new XPNUMDATAX field in arcGIS table and populate it using a prefix and APN
def makePNUMDATA(countyItem, boolItem, workspace, fc):

    prefix = 'default'

    arcpy.AddMessage(f"boolItem: {boolItem}")
    arcpy.AddMessage(f"countyItem: {countyItem}")

    if boolItem == "'true'":
        if countyItem == "'stanislaus'":
            ## Create variable used to modify APN
            prefix = ' '
        if countyItem == 'merced':
            ## Create variable used to modify APN
            prefix = 'M'

        ## Add XPNUMDATAX Field to the table
        arcpy.management.AddField(fc, 'XPNUMDATAX', 'TEXT')


        txFields = ['APN', 'XPNUMDATAX']

        ## Iterate table and update XPNUMDATAX field with prefix + APN
        with arcpy.da.Editor(workspace) as edit:
            ## Declare update cursor
            with arcpy.da.UpdateCursor(fc, txFields) as cursor:
                for row in cursor:
                    apnVal = row[0]
                    apnVal = str(apnVal)
                    newPNUM = [prefix + apnVal]
                    row[1] = newPNUM
                    cursor.updateRow(row)

This does create the XPNUMDATAX field, and through various print statements I have verified that it does indeed calculate the newPNUM value intended to populate the field.  However, I get this error:

Traceback (most recent call last):
  File "C:\Users\twhammond\Documents\tommy_misc\dataProject\testFiles\scripts\updateFromExcel3.py", line 274, in <module>
    makePNUMDATA(countyList[fcIndex], boolList[fcIndex], workspace, fcList[fcIndex])
  File "C:\Users\twhammond\Documents\tommy_misc\dataProject\testFiles\scripts\updateFromExcel3.py", line 230, in makePNUMDATA
    cursor.updateRow(row)
TypeError: value #1 - unsupported type: list

From all the documentation, it seems as if the cursor.updateRow() method takes a list or tuple as its parameter. 

twhammond_0-1688764612966.png

 

What am I missing here?  The row is a list object and is taken into a method that only accepts lists and tuples, so why am I getting this type error?

Other details:

I am using ArcGIS Pro 2.9.9

I am familiar with python but have only been using arcpy and arcGIS for a couple weeks.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings.

Since you are using a single field in the updatecursor, did you try a string instead of a list

newPNUM = prefix + apnVal

  


... sort of retired...

View solution in original post

2 Replies
DanPatterson
MVP Esteemed Contributor

A list (or tuple) of field names. For a single field, you can use a string instead of a list of strings.

Since you are using a single field in the updatecursor, did you try a string instead of a list

newPNUM = prefix + apnVal

  


... sort of retired...
twhammond
New Contributor II

I was completely misinterpreting the error.  I thought row was the parameter causing issues and didn't even notice that newPNUM was a list. 

Thanks! That solved the problem for me.

0 Kudos