Iterating field calculations in arcpy

المشرف العام

Administrator
طاقم الإدارة
I was successful in adding multiple fields using arcpy as follows:

div_fields = ("divpa_whea" , "divpa_maiz", "divpa_barl", "divpa_sorg", "divpa_sorg", "divpa_grou","divaa_whea", "divaa_maiz", "divaa_barl", "divaa_sorg", "divaa_sorg", "divaa_grou")for i in div_fields: arcpy.AddField_management(spam_tza60, i, "DOUBLE", "", "", "", "", "NULLABLE")Now what I want is loop through these existing fields listed in mult_fields variable below and fill values in the fields newly created div_fields variable. I was hoping something like the following would work, rather than using search cursors.

mult_fields = ("mpa_whea" , "mpa_maiz", "mpa_barl", "mpa_sorg", "mpa_sorg", "mpa_grou","maa_whea","maa_maiz", "maa_barl", "maa_sorg", "maa_sorg", "maa_grou")inFeature = "myFeature" for i in div_fields: for k in mult_fields: expression = "!k! * !k!" arcpy.CalculateField_management(inFeature, i, expression, "PYTHON")I however get the following error. I'd imagine it is the way I am specifying the expression that is giving me the error.

Traceback (most recent call last): File "", line 6, in File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\management.py", line 2727, in CalculateField raise eExecuteError: ERROR 000539: Invalid field mult_fieldsFailed to execute (CalculateField)

أكثر...
 
أعلى