Issue with calculate field in python

04-14-2020 11:17 AM
New Contributor II

Hello all! I am working on a python script tool, and seem to have run into an issue. 

The tool basically takes 2 feature classes, adds some fields to one, joins, then populates those fields, removes the join, then moves on to basically what you see here, repeated a number of times based on some rules I've come up with with respect to how additional records should be populated.

I have done extensive testing, and everything works until I get to this CalculateField function. My calculate fields seem to do absolutely nothing. The records will select correctly based on the SelectLayerByAttribute, but then nothing calculates. Its as if the tool skips the calculate steps in the first block. However, when I get to the second block where a space exists in the text to be calculated, "Toll Road", the tool fails and I receive the following error:

Traceback (most recent call last):
File "C:\Users\kn815rb\Documents\ArcGIS\DataUpdates_Downloads\NavTeq_Processing_Test\", line 38, in <module>
arcpy.CalculateField_management(newstreets, "TPK_SYMBL", "Toll Road", "VB", "")
File "c:\program files (x86)\arcgis\desktop10.6\arcpy\arcpy\", line 3654, in CalculateField
raise e
ExecuteError: ERROR 999999: Error executing function.
Expected end of statement
Failed to execute (CalculateField).

Failed to execute (NavTeqStreetProcessing).

I am guessing this means I am doing something wrong with my Calculate Fields, but I really cannot see what it is. Any ideas would be greatly appreciated!


import arcpy 

orgstreets = arcpy.GetParameterAsText(0) 
newstreets = arcpy.GetParameterAsText(1) 

arcpy.SelectLayerByAttribute_management(newstreets, "NEW_SELECTION", "\"RAMP\" = 'Y' AND \"FUNC_CLASS\" = '5'") 
arcpy.CalculateField_management(newstreets, "TPK_SYMBL", "Ramp", "VB", "") 
arcpy.CalculateField_management(newstreets, "GEOLAYER", "local_rds_nav", "VB", "") 

arcpy.SelectLayerByAttribute_management(newstreets, "NEW_SELECTION", "\"TPK_SYMBOL\" IS NULL AND \"TOLLWAY\" = 'Y' AND \"FUNC_CLASS\" = '3'") 
arcpy.CalculateField_management(newstreets, "TPK_SYMBL", "Toll Road", "VB", "") 
arcpy.CalculateField_management(newstreets, "GEOLAYER", "major_hwys_nav", "VB", "")‍‍‍‍‍‍‍‍‍
0 Kudos
2 Replies
MVP Emeritus

Is there a reason you are using a VB expression  instead of a python one?

CalculateField_management(newstreets, "TPK_SYMBL", "Toll Road", "VB", "")

New Contributor II

Its just what I know, I guess. Otherwise, no specific reason.

0 Kudos