[GIS] Calculate Field using variable in arcpy

arcpyfield-calculatorpython-parser

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.

Best Answer

Try passing your variable to your string:

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