How to calculate field as cursor name?

Discussion created by lucamoiana on Sep 14, 2012
Latest reply on Sep 17, 2012 by lucamoiana
First time dealing with cursor. I have lines intersecting polygons, I want to get a table with all attributes of the lines, add a field and calculate the field as the name of the polygon. I was able to get a table for each polygon but I can't get to calculate the field and add the polygon name. How do I do? here is my code:

import arcpy
arcpy.env.overwriteOutput = True

arcpy.env.workspace = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
ws = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Default.gdb'
Comuni = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Comuni'
Linee = 'C:\\Users\\a391665\\Documents\\ArcGIS\\Sardegna3.gdb\\Linee'

rows = arcpy.SearchCursor(Comuni)

for row in rows:
    print row.NOME
    feat = row.Shape
    arcpy.SelectLayerByLocation_management("Linee", "INTERSECT", feat, selection_type="NEW_SELECTION");
    out_feature_class = arcpy.ValidateTableName("Linee_Clip_" + row.NOME);
    table = arcpy.TableToTable_conversion("Linee", ws, out_feature_class);
    arcpy.AddField_management(out_feature_class, 'Clip', 'TEXT', '', '', '60');
    expression = arcpy.ValidateTableName(row.NOME);
    arcpy.CalculateField_management(table, "Clip", expression);

here is the error I get:

Empty value for ObjectID = 1 The calculated value is invalid for the row with ObjectID = 1. For example, the calculated value may be too large for the field or you may be trying to add a string to a number field. This row will not be updated.