I am new to scripting. I have been searching around on here and other sites, and can't seem to find something quite like what I need.
I am trying to find a max value within a field, and store that max value as a variable to get used for other processes later. I think I am defining the variable incorrectly, but I can't seem to find anything on how to define the max value of a field as a variable.
Here is what I have so far.
In this code, centerline is a variable that grabs a user defined feature class (this code is being set up as an Arc tool). SAMPINS is the name of the field that I am trying to grab the max value for. I realize that I can use statistics to get the max value (and maybe that is a better option here...), as well, but I still do not know how to define this as a variable.
The traceback error is telling me that addfields is not defined on line 179. Line 179 is the line that reads "addfields - 1 < [SAMPINS]".
addfields = 0 fieldtag = str(addfields) with arcpy.da.SearchCursor(centerline, "SAMPINS") as cursor: for row in cursor: value = row if value > addfields: addfields = value while (addfields > 1): arcpy.AddField_management(centerline, "F_"+fieldtag, "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "") if addfields: addfeilds - 1 < [SAMPINS] arcpy.CalculateField_management(centerline, "F_"+fieldtag, "[SAMPINS] + [SAMPDIST] + [SAMPLF]", "VB", "") else: arcpy.CalculateField_management(centerline, "F_"+fieldtag, "0", "VB", "") addfields = addfields - 1