I am writing a script assigning the ADMINAREA value to the empty LOCALITY fields from TWB_Suburbs to TWB_Property layer. I am getting:

ValueError: need more than 1 value to unpack

Is anyone able to help out?

import arcpy
# set overwrite true so that if data already exists it overwrite
arcpy.env.OVERWRITE = True
arcpy.env.overwriteOutput = True

# make query for empty LOCALITY values
query = '"LOCALITY" = \' \''

# assign workspace
arcpy.env.workspace = "C:\Users\data"

# make feature layer from property shape file, apply empty locality values query
arcpy.MakeFeatureLayer_management("TWB_Property.shp", "TWB_Property_Layer", query)

# make feature layer for suburbs shape file
arcpy.MakeFeatureLayer_management("TWB_Suburbs.shp", "TWB_Suburbs_Layer")

# Select empty properties in Properties layer WITHIN Suburbs layer
arcpy.SelectLayerByLocation_management ("TWB_Property_Layer", "WITHIN", "TWB_Suburbs_Layer")

#create empty list
suburbList = []

# iterate over admin layer field values, to get it's value
with arcpy.da.SearchCursor("TWB_Suburbs_Layer",["ADMINAREA"]) as rows:
    for row in rows:
        print (row[0])

#get the number of selected land parcels
numberSuburbs = len(suburbList)


# Create Update Cursor to update missing LOCALITY fields in property layer
for parcel in range (0, numberSuburbs):        
    with arcpy.da.UpdateCursor("TWB_Property_Layer", "LOCALITY") as initialRows:
        for initialRow, rowTwo in initialRows:
                rowTwo[0] = row[0]

# Print number of fields updated for each suburb           
    print ('Suburb, Number of updated properties' .format(row[0], row[1]))
    print ("{row}" + str(numberSuburbs) +
           .format(row[0], row[1]))

    #report success message
    arcpy.AddMessage("Well done!")
  • Your Python logic is non-Pythonic. If you want just the first two rows, you could use next to request them, or you could slice the list ( which could be much slower if there are a large number of rows). – Vince Apr 14 at 13:02

You do not provide us with the line number on which the error occurs but I am confident that it will be this one:

    for initialRow, rowTwo in initialRows:

You are getting the error because you are trying to set two variables (initialRow and rowTwo) when only one value (a tuple) is being provided by initialRows at each iteration of the for loop.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.