First off, I know there's a better title I could have used so I apologize for the confusion.
I have a short script I've written that takes a some user entered information parcel data a field the calculation will be done for.
# Import arcpy module
import arcpy
# Script arguments
Parcels = arcpy.GetParameterAsText(0)
Field2Calc_for = arcpy.GetParameterAsText(1) #field type derived from Parcels
lengthField = arcpy.GetParameterAsText(2) #field type derived from Parcels
widthField = arcpy.GetParameterAsText(3) #field type derived from Parcels
num = arcpy.GetParameterAsText(2) #Long Type
# Local variables
expression = r'reclass' + str((r'!' + + widthField + r'!', r'!' + lengthField + r'!' , num))
codeblock = """ def reclass(lengthField,widthField,num):
if ((lengthField/num) >= (widthField)):
return 'True'
else:
return '' """
# Process: Calculate Field
arcpy.CalculateField_management(Parcels, Field2Calc_for, expression, "PYTHON", codeblock)
I'm having a difficult time figuring out how to correctly set the string for the expression variable. What I'd like to do is take my user input lengthField & widthField parameters and use variable substitution in the expression variable. I'm having a hard time figuring out if that's possible and what the syntax would look like. The examples for the the CalculateField_management method have the field name hard coded into the script, but I'd like to try to avoid that if possible so the user can choose the field.
I appreciate any help and I'm pretty sure it's just something dumb that I'm overlooking b/c that's usually the case.
Thanks,
Mark