Select to view content in your preferred language

Python Scripting Problem

352
1
03-13-2014 09:48 AM
H_A_D_Padmasiri
Deactivated User
Dear Sir
I want to replace "TextString" field attribute values with "Name_Sin" attribute values in an another table.
for that  I wrote a script to join two tables and calculate the attributes. But the expression is something wrong.
I have no idea to correct it. So please  help me to correct it.

Thanks

Padmasiri

My Script
arcpy.MakeFeatureLayer_management("PCL_Anno", "PCL_Anno_Lyr")
arcpy.AddJoin_management("PCL_Anno_Lyr", "Text", r"C:\CMSupport.gdb\Conv_Tab", "Nam_Idm", "KEEP_ALL")
arcpy.CalculateField_management("PCL_Anno_Lyr", "TextString", "!TextString! = !Name_Sin!", "PYTHON_9.3", "")
arcpy.CopyFeatures_management("PCL_Anno_Lyr", "PCL_Anno_New")

Error Message
Traceback (most recent call last):
  File "E:\Gampaha\Scripts\Script1.py", line 89, in <module>
    arcpy.CalculateField_management("PCL_Anno_Lyr", "TextString", "!TextString! = !Name_Sin!", "PYTHON_9.3", "")
  File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3128, in CalculateField
    raise e
ExecuteError: ERROR 000539: SyntaxError: invalid syntax (<expression>, line 1)
Failed to execute (CalculateField).

Failed to execute (LISTool1.0).
Tags (2)
0 Kudos
1 Reply
AdamCox1
Deactivated User
I think there are two problems.  First, the expression you enter need only be what you would use in field calculator, i.e. "!Name_Sin!", instead of "!TextString! = !Name_Sin!".  Second, when you have a joined table, the name of the feature class and a period are added to the field name as a prefix.  So, when you have this table joined, you will want to write "!<feature class name>.Name_Sin!".  The easiest way to double check this is to perform the join in ArcMap, and then open the table and view the properties of various fields to see their respective names.

Hope that solves it!
Adam
0 Kudos