CalculateField with variables

المشرف العام

Administrator
طاقم الإدارة
I'm trying to make a python script on arcmap 10.2.2 which will copy values from an old field (selected by the user) and paste them in an new field (named by the user).I wrote that:

fc = arcpy.GetParameterAsText(0)layerforNewField =arcpy.GetParameterAsText(1)newfieldname =arcpy.GetParameterAsText(2)oldfield = arcpy.GetParameterAsText(3)calculate = "!oldfield!"# Import system modulesimport arcpyfrom arcpy import envenv.workspace = fc#add new field with "double type"arcpy.AddField_management(layerforNewField, newfieldname, "DOUBLE", 10, 4)#copy/paste values from a fieldarcpy.CalculateField_management(layerforNewField, newfieldname, calculate, "PYTHON_9.3")Results: the new field is created, but the values didn't paste. The same script without variables is working. What's wrong? I think there is a problem on "calculate" variable, isn't it?

I have also tried:

arcpy.CalculateField_management(layerforNewField, newfieldname, '!' + calculate + '!', "PYTHON_9.3")and:

arcpy.CalculateField_management(layerforNewField, newfieldname, """!{}!""".format(calculate), "PYTHON_9.3") with the same results

أكثر...
 
أعلى