Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to add (ie "Author", "LastUpdated") to feature classes within a gdb and then populate each of those fields. I have been able to get my code to run properly for the numerical field but I cannot get it to run for the text field.

    fcList = arcpy.ListFeatureClasses()
    fieldName1 = "Author"
    expression1 = "John Doe"

    for fc in fcList:    

            arcpy.AddField_management(fc,fieldName1, "TEXT")

            arcpy.CalculateField_management(fc, fieldName1, expression1, "PYTHON")

My code returns this error:

ExecuteError: ERROR 000539: <type 'exceptions.SyntaxError'>: unexpected EOF while parsing (<expression>, line 1)
Failed to execute (CalculateField).

How can I fix this? Thanks!!

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

You have to include quotes within your expression string. Try this:

fcList = arcpy.ListFeatureClasses()
    fieldName1 = "Author"
    expression1 = "\"John Doe\""

    for fc in fcList:    

            arcpy.AddField_management(fc,fieldName1, "TEXT")

            arcpy.CalculateField_management(fc, fieldName1, expression1)

By adding in escaped double quotes, your field will be sent the string "John Doe" instead of John Doe without quotes. For text fields, the quotes are required.

share|improve this answer
    
That did the trick! Thanks a ton egdetti! –  kkaszas Oct 11 '12 at 22:21
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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