Select to view content in your preferred language

Referencing a python variable in an arcade expression

156
2
a month ago
Labels (2)
BSkaflen
New Contributor

I have a python script which I am using to automate an otherwise tedious serious of intersects, joins and calculate fields. As part of this, I am calculating a field, DF_Sev, which is reliant upon a field which will be from one of the intersect functions (call it Field B). Field B is not guaranteed to have the same name each time this script is run, and is therefore stored as a variable. However, within the calculate field function for DF_Sev, the variable for Field B is not recognized within the arcade expression i am using. Is there a way for this field to be passed to the arcade expression, or do i need to find another workaround?

0 Kudos
2 Replies
AlfredBaldenweck
MVP Regular Contributor

Try using an F string

fieldVar = [f.name for f in arcpy.ListFields(fc)][0] # or whatever

arcEx = f"Text($feature.{fieldVar}) + "\n" + $feature.OBJECTID)
0 Kudos
BSkaflen
New Contributor

I was able to get around it by switching to a python expression, but I'll give this a shot as well!

0 Kudos