Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

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

$
0
0
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:
outTable = r'D:\test.dbf'
dateField = 'Date'
fieldLength = 20
part = os.path.split(ascii)[1]
fieldValue = os.path.splitext(part)[0]
arcpy.AddField_management(outTable, dateField, "TEXT", "", "", fieldLength)
arcpy.CalculateField_management(outTable, dateField, fieldValue)

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!

Viewing all articles
Browse latest Browse all 2485

Trending Articles