0

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.

1 Answer 1

0

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"'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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