AnsweredAssumed Answered

Syntax when passing variable to calculate field expression

Question asked by LANDVEST on Sep 14, 2016
Latest reply on Sep 14, 2016 by mbabinski1988

OK, so I feel like I've tried just about everything here. What I'm looking to do is to concatenate a iteration value (?) from a search cursor with the object ID of a feature class to create a unique ID field. I want these two values separated by a hyphen '-'. Target field (PLOT_ID) is obviously a string. There is what I've got working so far.

 

 

i = 1

ptCur = arcpy.da.SearchCursor (ptFC, fldLst)

for row in ptCur:

[various things happen removed for brevity]

Cluster_Plot = str(i) + '!OBJECTID!'

arcpy.AddMessage(Cluster_Plot)

arcpy.CalculateField_management(outPointsDissolve,"PLOT_ID",Cluster_Plot,"PYTHON_9.3")

things are appended to a a target FC and the target field looks like this:

 

So it appears to be treating the expression inputs as strings. From here I've tried to get a - in between the two values with no luck....even when converting the OID to a string : 'str(!OBJECTID!)'   I just can't get things to escape right i guess. Things I've tried:

Cluster_Plot = str(i) + '-' + '!OBJECTID!'

Here the  hyphen apparently is interpreted as an operator:

 

Cluster_Plot = str(i) + " + '-' + " + '!OBJECTID!'

 

Cluster_Plot = str(i) + " + '-' + " + 'str(!OBJECTID!)'

I dont get this because you can use the + operator in the field calculator just fine (if you format the field as a string using str)

 

Could someone please help me out of my misery here?

Outcomes