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):

fieldMappings = arcpy.FieldMappings()
for field in fieldMappings.fields:
    if field.name not in ['Type']:

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.

2 Answers 2


I was able to find the answer to my question from ArcPy calculating string field gives ERROR 999999

The issue was in my expression list. The original did not include '' around the field value ie '"FIELD_VALUE"'.


Since this post two new tools have been added to the toolbox that will simplify your code. They are Add Fields and Calculate Fields. This may be of interest to others seeking similar solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.