4

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.

1
  • 1
    var_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
    May 9, 2016 at 19:21

1 Answer 1

8

Try passing your variable to your string:

var_a = 6.2
arcpy.CalculateField_management (in_table, in_field,"[FIELD_A]*100/{}".format(var_a))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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