0

I have this table:

Initial table

And I want to create a field called "COSN2" which after the creation I want to fill it with three characters from the field "COS207". Than I wrote the following script:

import arcpy, os
from arcpy import env, UpdateCursor
from arcpy.management import AddField

arcpy.env.overwriteOutput=True
arcpy.env.workspace="C:\Users\Thomas\Desktop\Trabalho AE\Trabalho.gdb"
fc="COS2007"

arcpy.AddField_management(fc,"COSN2","TEXT","","","","NULLABLE")
arcpy.CalculateField_management(fc,"COSN2","LEFT([CONS2007],3)","VB")

cursor=arcpy.SearchCursor(fc)
for row in cursor:
    print row.COS2007+" ; "+row.COSN2

Then the eclipse returns me an error:

Traceback (most recent call last):
File "F:\MSIGOT\AE\AnaliseEsp\TrabalhoAE\COSN2.py", line 10, in <module>

arcpy.CalculateField_management(fc,"COSN2","LEFT([CONS2007],3)","VB")
File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\management.py", line 3360, in CalculateField
raise e
arcgisscripting.ExecuteError: ERROR 999999: Error executing function.
Failed to execute (CalculateField).

I've tried to change "VB" (above) to "PYTHON" and "PYTHON_9.3" but the error persists.

Can anyone explain this?

1
  • Welcome to GIS SE! As a new user please take the tour to learn about our focused Q&A format.
    – Midavalo
    Commented Jun 5, 2017 at 19:51

1 Answer 1

2

You have a typo. Your field name in your screenshot is COS2007 but in your python you've called it CONS2007

arcpy.CalculateField_management(fc,"COSN2","LEFT([CONS2007],3)","VB")
                                                    ^

Also note that you have created your new field CONS2 with an alias of NULLABLE

You need to add another "" before the "NULLABLE"

arcpy.AddField_management(fc, "COSN2", "TEXT", "", "", "", "NULLABLE")

should probably be

arcpy.AddField_management(fc, "COSN2", "TEXT", "", "", "", "","NULLABLE")
1
  • Thanks a lot man! I'm a beginner and this errors is have happened somtimes... xD Commented Jun 5, 2017 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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