The row contains a bad value

2667
2
Jump to solution
04-21-2021 03:04 PM
2Quiker
Occasional Contributor II

I have the following and I having a hard time by passing some blank attributes. I know what the problem is, the problem is that row Pin has blanks and when the codes tries to populate the Permits row it throws the 'The row contains a bad value' Error. It's trying to bunch all of 'P_num' that have a blank  into the Permits row. How can I get passed this?

 

dict1 = dict()
with arcpy.da.SearchCursor(fc,['Pin','Perm_COUNT','P_Num']) as cursor:
    for row in cursor:
        if row not in (None, "", " "):
            dict1.setdefault(row[0],[]).append(str(row[2]))
            #print (dict1)

with arcpy.da.UpdateCursor(fc,['Pin','Perm_COUNT','Permits']) as cursor:
    for row in cursor:          
        row[2] = ",".join(dict1[row[0]])
        #print (",".join(dict1[row[0]]))
        cursor.updateRow(row)
0 Kudos
1 Solution

Accepted Solutions
RandyBurton
MVP Alum

The search cursor is returning a tuple of 3 elements matching the three fields requested.  The check for None is being done on the tuple when it should be the first element which matches the 'Pin' field.  Try:

with arcpy.da.SearchCursor(fc,['Pin','Perm_COUNT','P_Num']) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "): # row[0] checks 'Pin'

View solution in original post

2 Replies
RandyBurton
MVP Alum

The search cursor is returning a tuple of 3 elements matching the three fields requested.  The check for None is being done on the tuple when it should be the first element which matches the 'Pin' field.  Try:

with arcpy.da.SearchCursor(fc,['Pin','Perm_COUNT','P_Num']) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "): # row[0] checks 'Pin'
2Quiker
Occasional Contributor II

Duh, I feel dumb. Got it working with the following with your help, thanks!

dict1 = dict()
with arcpy.da.SearchCursor(fc,['Pin','Perm_COUNT','P_Num']) as cursor:
    for row in cursor:
        if row[0] not in (None, "", " "): # forgot the [0]
            dict1.setdefault(row[0],[]).append(str(row[2]))
            #print (dict1)

with arcpy.da.UpdateCursor(fc,['Pin','Perm_COUNT','Permits']) as cursor:
    for row in cursor:
        if row[0] in dict1: #added to pass only attributes in dict
            row[2] = ",".join(dict1[row[0]])
            #print (",".join(dict1[row[0]]))
            cursor.updateRow(row

 

0 Kudos