Calculate Field in ArcGIS Pro 2.7 Python Stand-Alone Fails

264
1
Jump to solution
01-06-2022 11:35 AM
GerryGabrisch
Occasional Contributor III

I am trying to execute a calculate field in arcpy from ArcGIS Pro 2.7.  Here is the relevant code.

#a confirmed existing shapefile ....

out_fc = r'C:\GIS\telemetrytags\individual_fish_individual_days\112_2019-04-12.shp'

# a confirmed and working add field....

arcpy.AddField_management(out_fc, 'TagID', "SHORT")

#The existing field name...
tagid = "TagID"

#The value to populate TagID with...in this case the value of tag is a float (with a value of 112.0) before I #convert it to an int and then string.
value = str(int(tag))

#code fails here with the message below.
arcpy.CalculateFields_management(out_fc, tagid, value, "PYTHON3")

Error Info:
Failed to execute. Parameters are not valid.
ERROR 000800: The value is not a member of Python 3 | Arcade.
ERROR 000728: Field 112 does not exist within table
Failed to execute (CalculateFields).

112 is the value I am trying to populate field TagID with and not the field name so I do not understand what is up with that error.

Another oddity - when I add my shapefile to ArcGIS pro and check the TagID field it returns that the field is a type Long with is not what I am doing with the calculate field.

 

Why is this 'the most simple of calculations' failing in arcpy for ArcGIS Pro 2.7

 

 

0 Kudos
1 Solution

Accepted Solutions
Luke_Pinner
MVP Regular Contributor

You're trying to use the syntax for Calculate Field with the Calculate Fields tool. The syntax for Calculate Fields is:

 

arcpy.CalculateFields_management(in_table, expression_type, fields, {code_block}, ...)
#Or
arcpy.management.CalculateFields(in_table, expression_type, fields, {code_block}, ...)

 

 

The syntax for Calculate Field is:

 

arcpy.management.CalculateField(in_table, field, expression, {expression_type}, {code_block}, etc...)
#Or
arcpy.CalculateField_management(in_table, field, expression, {expression_type}, {code_block}, etc...)

 

 

As you're only calculating a single field, just change to using the Calculate Field tool:

 

arcpy.CalculateField_management(out_fc, tagid, value, "PYTHON3")
#Or
arcpy.management.CalculateField(out_fc, tagid, value, "PYTHON3")

 

 

 

 

View solution in original post

0 Kudos
1 Reply
Luke_Pinner
MVP Regular Contributor

You're trying to use the syntax for Calculate Field with the Calculate Fields tool. The syntax for Calculate Fields is:

 

arcpy.CalculateFields_management(in_table, expression_type, fields, {code_block}, ...)
#Or
arcpy.management.CalculateFields(in_table, expression_type, fields, {code_block}, ...)

 

 

The syntax for Calculate Field is:

 

arcpy.management.CalculateField(in_table, field, expression, {expression_type}, {code_block}, etc...)
#Or
arcpy.CalculateField_management(in_table, field, expression, {expression_type}, {code_block}, etc...)

 

 

As you're only calculating a single field, just change to using the Calculate Field tool:

 

arcpy.CalculateField_management(out_fc, tagid, value, "PYTHON3")
#Or
arcpy.management.CalculateField(out_fc, tagid, value, "PYTHON3")

 

 

 

 

0 Kudos