TypeError: value #1 - unsupported type: list

2209
4
Jump to solution
05-03-2021 02:39 PM
JaredPilbeam2
MVP Regular Contributor

I'm trying to slice with an index to get everything that comes after the first value in the MAIL_AD1 field and use the update cursor to put it in the Name_First field. As of now I can only get the second value and nothing more.

Here's the table I'm working with:
tab1.png

 

This puts the correct value in the Name_Last field:

 

fc = r"C:/pathto/fc"
field = ['MAIL_AD1', 'Name_First', 'Name_Last']

def Name_Last(): # this function updates the Name_Last field
    with arcpy.da.UpdateCursor(fc, field) as cursor:
        for row in cursor:
            name = row[0] #get name in MAIL_AD1 list
            if name is None:  continue  # continue to the next iteration in loop if None
            s = str(unit).split() #split strings in MAIL_AD1 field 
            row[2] = s[0] #update Name_Last field with first value in MAIL_AD1 field
            cursor.updateRow(row)
    del cursor 

 

 

But when I try to slice with an index number I get the error, which happens on the row[1] = s[1:] line.

 

def Name_First(): #this function updates the Name_First field
    with arcpy.da.UpdateCursor(fc, field) as cursor:
        for row in cursor: 
            unit = row[0] #get Unit in field list
            if unit is None:  continue  # continue to the next iteration in loop if None
            s = str(unit).split() #split strings in MAIL_AD1 field 
            row[1] = s[1:] #update Name_First field with what comes after first value in MAIL_AD1 field
            cursor.updateRow(row)
    del cursor 
TypeError: value #1 - unsupported type: list

 

 

0 Kudos
1 Solution

Accepted Solutions
Tomasz_Tarchalski
New Contributor III

 

 

s = str(unit).split() # it returns list of ['Lovato', 'Dennis', 'J']
b = s[1:] # returns a list of ['Dennis', 'J']
# so in fact you must again convert list into string like this
c = " ".join(b) # it should retourn a string "Dennis J". you joined by space
#or
c = ", ".join(b) # should retourn "Dennis, J".

 

 

Advice: for this kinds of test run python directly in command line and test it. Or install Visual Studio code, install Python extention and run debugging.  or test in arcgis pro notebook...

Regards, Tomasz

View solution in original post

0 Kudos
4 Replies
Tomasz_Tarchalski
New Contributor III

Your slicing retourns list (s[1:]) with one value, but you cannot insert it into row. Just replace s[1:] with s[1:][0]

JaredPilbeam2
MVP Regular Contributor

@Tomasz_Tarchalski
If I run

row[1] = s[1:][0]
print(row[1])

it's only returning one value.

DENNIS
KYLE
LINDA
SUSAN
MICHAEL
NEILL
PAMELA
...

 

 This is what I'm expecting:

DENNIS J
KYLE 
LINDA KAY LVG TR
SUSAN K
MICHAEL JO ANN
NEILL DANIEL J
PAMELA
...

 

If I do this it's back in a list again.

row[1] = s[1:][0:]
print(row[1])

Prints:

['DENNIS', 'J']
['KYLE']
['LINDA', 'KAY', 'LVG', 'TR']
['SUSAN', 'K']
['MICHAEL', 'JO', 'ANN']
['NEILL', 'DANIEL', 'J']
['PAMELA']
...

 

0 Kudos
Tomasz_Tarchalski
New Contributor III

 

 

s = str(unit).split() # it returns list of ['Lovato', 'Dennis', 'J']
b = s[1:] # returns a list of ['Dennis', 'J']
# so in fact you must again convert list into string like this
c = " ".join(b) # it should retourn a string "Dennis J". you joined by space
#or
c = ", ".join(b) # should retourn "Dennis, J".

 

 

Advice: for this kinds of test run python directly in command line and test it. Or install Visual Studio code, install Python extention and run debugging.  or test in arcgis pro notebook...

Regards, Tomasz

0 Kudos
JaredPilbeam2
MVP Regular Contributor

Thanks @Tomasz_Tarchalski .

I was asleep at the wheel.

0 Kudos