1

I tried this code in ArcGIS Pro.

I am getting the code to work great in command line. However, trying to script a tool out it in ArcGIS Pro.

Getting an error:

File "", line 13, in AttributeError: 'str' object has no attribute 'extend'.

Here is the code:

import arcpy
#input data and fields to find maximum
table = arcpy.GetParameterAsText(0)
fields = arcpy.GetParameterAsText(1)
n = len(fields)
# Add fields to input table to store maximum and field name
maxfield = arcpy.GetParameterAsText(2)
maxname = arcpy.GetParameterAsText(3)
arcpy.AddField_management(table, maxfield, "DOUBLE")
arcpy.AddField_management(table, maxname, "TEXT"
fields2 = fields[:] # shallow copy
fields2.extend([maxfield, maxname])
with arcpy.da.UpdateCursor(table, fields2) as cursor:
 for row in cursor:
 # Look at the first n values
 check = row[:n]
 maxval = max(check)
 # Get the index position of the maxval and use it slice into field list
 # which gives us the field name
 # only update the last two rows
 row[-2:] = maxval, fields[check.index(maxval)]
 cursor.updateRow(row)
TomazicM
27.3k25 gold badges33 silver badges43 bronze badges
asked Apr 24, 2023 at 6:52

1 Answer 1

1

You are using GetParamterAsText, so the input fields variable is a string. If you print the fields variable using arcpy.AddMessage you will see how the GetParameterAsText handles the multiple field inputs as text. Convert the input string to a list.

fields = arcpy.GetParameterAsText(1).replace("'", "").split(";")
answered Apr 24, 2023 at 9:38
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.