Skip to content

Instantly share code, notes, and snippets.

@tjmichael81
Created January 4, 2016 14:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjmichael81/aec863a9f48aca201ac3 to your computer and use it in GitHub Desktop.
Save tjmichael81/aec863a9f48aca201ac3 to your computer and use it in GitHub Desktop.
Use arcpy.CalculateField_management to concatenate two fields with a separator
import arcpy
fc = '<path to fc or table>'
field_CommonName = 'Field_CommonName'
field_BotanicalName = 'Field_BotanicalName'
# Takeaway - enclose the entire expression in quotes, don't do this:
# commonNameExpression = !Field_Name! + ' - ' + !Current_Crop_2013!
commonNameExpression = "!Field_Name! + ' - ' + !Current_Crop_2013!"
botanicalNameExpression = "!Field_Name! + ' - ' + !Current_Crop_2013_Botanical!"
arcpy.CalculateField_management(fc, field_CommonName, commonNameExpression, 'PYTHON_9.3')
arcpy.CalculateField_management(fc, field_BotanicalName, botanicalNameExpression, 'PYTHON_9.3')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment