Python Calculate Field Management String Variable Formatting

2388
2
09-24-2014 08:02 AM
GeoffOlson
Occasional Contributor

I'm trying to calculate a field using the Python window, but I can't seem to figure out how to format the function properly.  What's the correct syntax for using a string variable as the expression?

 

arcpy.CalculateField_management(mapLyr2, "Jurisdicti", "'{0}'.format(tName)", "PYTHON")

 

I couldn't find an example that answered this question for me.  Thanks in advance.

0 Kudos
2 Replies
GeoffOlson
Occasional Contributor

I found a work around, but it doesn't solve the question of formatting.  If I change the variable to have double quotes it accepts it.  I have to format the variable with the quotation marks wrapped in triple apostrophes, like this:

cName = '''"{0}"'''.format(tName)

0 Kudos
RiyasDeen
Occasional Contributor III

Hi Jeoff,

Try

arcpy.CalculateField_management(mapLyr2, "Jurisdicti", "\"{0}\"".format(tName), "PYTHON")