I've got a problem with my script and hope that someone can help me.
What I ́d like to do is using the field calculator to calculate values for a field using values from another field and a variable in the expression. The script should be as follows:
var_a = 6.2
arcpy.CalculateField_management (in_table, in_field,"[FIELD_A]*100/var_a")
[FIELD_A]
contains the values of another field in the same table.
I only know how to integrate var_a in the expression using
arcpy.CalculateField_management (in_table, in_field, "'"+str(var_a)+"'", "PYTHON")
but then I can ́t use the other values for the calculation.
-
1var_a is being seen as just as characters, use either the .format() string method to reference the variable in the expression or use AddFieldDelimiters to help format the expression (pro.arcgis.com/en/pro-app/arcpy/functions/…).artwork21– artwork212016年05月09日 19:21:10 +00:00Commented May 9, 2016 at 19:21
1 Answer 1
Try passing your variable to your string:
var_a = 6.2
arcpy.CalculateField_management (in_table, in_field,"[FIELD_A]*100/{}".format(var_a))
Explore related questions
See similar questions with these tags.