I would like to extract a string of characters between two underscores. The number of characters between and on each side of the '_' will vary, but there will only ever be two underscores. The long field with underscores is a text field, the field to be filled in is a short integer. I've been able to parse out the characters before and after the underscores and fill other fields in the feature class, but have been unable to place the middle section into a new field.
Example 1: 102_1204_234324
I want to return '1204'
Example 2: 324423_1_342
I want to return '1'
I've tried a number of variations and the one that I think should work is:
# Import system modules
import arcpy
#from arcpy import env
# Set environment settings
arcpy.env.workspace = "c:/temp/testing.gdb"
# Set local variables
inFeatures = "testFeature"
fieldName = "testField"
expression = "!parse_field!.split('_')[1::2]"
# Execute CalculateField
arcpy.CalculateField_management(inFeatures, fieldName, expression, "PYTHON", "")
Which I would think would create a list, then return every second element of the list. However the field to be filled in (testField) is still empty.
Thanks -al