AnsweredAssumed Answered

Python CalculateField sometimes doesn't work depending on field value variable

Question asked by pfroemke on Dec 30, 2013
Latest reply on Dec 31, 2013 by pfroemke
I'm trying to add and calculate a text field in an existing dbf table by using a variable to set the value of the field. The AddField code is working fine. The CalculateField code sometimes does not work depending on the value of the variable I'm using to calculate the field.

My statements (inside a for loop) to add and calculate the field are:
for ascii in rasterList:[INDENT]outTable = r'D:\test.dbf'[/INDENT]
[INDENT]dateField = 'Date'[/INDENT]
[INDENT]fieldLength = 20[/INDENT]
[INDENT]part = os.path.split(ascii)[1][/INDENT]
[INDENT]fieldValue = os.path.splitext(part)[0][/INDENT]
[INDENT]arcpy.AddField_management(outTable, dateField, "TEXT", "", "", fieldLength)[/INDENT]
[INDENT]arcpy.CalculateField_management(outTable, dateField, fieldValue)[/INDENT]

If I set fieldValue = os.path.splitext(part)[0], it does not work--the field remains blank. If I print fieldValue, I get ECR_TXT_201304, which is correct--it's what I want stored in the Date field for all records in the table.
If I set fieldValue = "201304", it works--the Date field gets populated with 201304.
I even tried fieldValue = str(os.path.splitext(part)[0]), and that didn't work either.
I never get any error messages, the script runs without any indication of a problem.

I'm baffled at this point why this code doesn't work when using the os.path variable.
Thank you for any help!