Below is how I used the Update Cursor in my final script. As you can see getValue was used a few times, perhaps there is a cleaner way to do this? But my concatenated field wouldn't populate properly otherwise.
sourceRows = arcpy.UpdateCursor(inFeatures)
source = sourceRows.next()
while source:
fieldString1 = source.getValue(fieldName1)
fieldString2 = source.getValue(fieldName2)
concatString= (str(source.getValue(fieldName2))[1:7] + str(source.getValue(fieldName1))[1:7])
source.setValue(fieldName3, concatString)
sourceRows.updateRow(source)
source = sourceRows.next()
del source, sourceRows
I have a script that creates three fields in a feature class. The script adds the X and Y coordinates to the first two fields. I would like data found in the middle parts of the first two fields to populate the third field. Does anyone know how to find the middle part of a field using Python? I see where VBScript seems to have a MID function but I haven't found anything for Python yet. Below is what the third field (fieldName3) should look like.
fieldName1 fieldName2 fieldName3
12345.321 36789.321 67892345
24680.5425 98765.432 87654680
Do you see how I want data to be combined in fieldName3? Below is the script as I have it now.
import arcpy
from arcpy import env
arcpy.env.overwriteOutput = True
env.workspace = "D:/gisfiles/test.gdb/"
inFeatures = "fc"
fieldName1 = "xCoord"
fieldName2 = "yCoord"
fieldName3 = "Combined"
fieldPrecision = 18
fieldScale = 11
expression1 = "float(!SHAPE.CENTROID!.split()[0])"
expression2 = "float(!SHAPE.CENTROID!.split()[1])"
arcpy.AddField_management(inFeatures, fieldName1, "DOUBLE", fieldPrecision, fieldScale)
arcpy.AddField_management(inFeatures, fieldName2, "DOUBLE", fieldPrecision, fieldScale)
arcpy.AddField_management(inFeatures, fieldName3, "DOUBLE", fieldPrecision, fieldScale)
arcpy.CalculateField_management(inFeatures, fieldName1, expression1,
"PYTHON")
arcpy.CalculateField_management(inFeatures, fieldName2, expression2,
"PYTHON")
sourceRows = arcpy.UpdateCursor(inFeatures)
source = sourceRows.next()
while source:
**#Instead of 12345 I need an expression to combine fieldName1 and fieldName2**
source.setValue(fieldName3, "12345")
sourceRows.updateRow(source)
source = sourceRows.next()
del source, sourceRows