I have three shapefiles as points that I am trying to create new fields for and fill in the fields with a string descriptor. I am then trying to merge all three point files deleting every field but keeping the type field. The code is below:
fieldnames = ['Type','Type','Type']
shapefiles = ['Flowpp1.shp','RoadPP1.shp','InletPP.shp']
expression = ["Stream","Road",'!Element!']
for i,x,j in zip(shapefiles,fieldnames,expression):
arcpy.AddField_management(i,x,"TEXT",25,"","","","")
arcpy.management.CalculateField(i,x,j,'PYTHON',"TEXT")
fieldMappings = arcpy.FieldMappings()
fieldMappings.addTable(shapefiles)
for field in fieldMappings.fields:
if field.name not in ['Type']:
fieldMappings.removeFieldMap(fieldMappings.findFieldMapIndex(field.name))
arcpy.management.merge(shapefiles,home + '/PourPoints.shp', filedMappings)
I am running into a name error when I get to the arcpy.management.CalculateField function.
What am I doing wrong?
The error is:
ExecuteError: ERROR 000539: Error running expression: Stream Traceback (most recent call last): File "", line 1, in NameError: name 'Stream' is not defined
The goal is for the type filed for Flowpp1.shp to be "Stream", Roadpp1 to be "Road", and Inlet.shp to be the row equivalent value in the !Element! field.