AnsweredAssumed Answered

add and calculate field

Question asked by melodykee on Sep 29, 2011
Latest reply on Sep 30, 2011 by melodykee
I want to add a field "filename" with "TEXT" format for a shape file and assign this field with the file name. The shape file only has one record. Here is my code:

import arcpy
from arcpy import env

# Set environment settings
env.workspace = "D:/Workspace"

fc = "01055p.shp"
tmp = fcname.split('.')
tmp2 = tmp[0]

arcpy.AddField_management(fc, "filename", "TEXT", "", "", 25)
arcpy.CalculateField_management(fc, "filename", tmp2)

But I got error saying "CalculateField_management" failed to execute. Is there any problem with the script? Thanks!

Outcomes