I have written the following script to iterate it as a tool for all my tables with ModelBuilder, but i have a problem wth my codeblock. I want to add a field FID to all my tables and to add the values 0,1,2,3,4... for all rows of table. Each table has different number of rows. I am using ArcGIS 10.2.2 for Desktop.
The code i have written is this.
# Import system modules
import arcpy
import os
from arcpy import env
arcpy.overwriteoutput = True
# Set environment settings
inWorkspace = arcpy.GetParameterAsText(0)
inTable = arcpy.GetParameterAsText(1)
outTable = arcpy.GetParameterAsText(2)
data_type = ""
# Set local variables
# fieldName1
# fieldName2
fieldName1 = "FID_1"
fieldName2 = "Same"
arcpy.AddField_management(inTable, fieldName1, "DOUBLE", "", "", "", "", "NON_NULLABLE")
arcpy.AddField_management(inTable, fieldName2, "DOUBLE", "", "", "", "", "NON_NULLABLE")
arcpy.Copy_management(inTable, outTable, data_type)
# Calculate Field FID_1
fieldname = fieldName1
expression = "getCalc(!FID_1!)"
codeblock = """def getCalc(FID_1):
FID_1 = 1
for row in FID_1:
FID_1 = FID_1 + 1
return FID_1"""
# Execute CalculateField
arcpy.CalculateField_management(inTable, fieldname, expression, "PYTHON_9.3", codeblock)
I am newbie in Python.