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.

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))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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