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.

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked May 9, 2016 at 19:15
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/…). Commented 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))
answered May 9, 2016 at 19:19
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.