Skip to main content
"update" cursor, not "insert" cursor.
Source Link
Jason Bellino
  • 4.3k
  • 27
  • 35

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insertupdate cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

@user2856159's answer is also good, I'd be curious to see if one method is any quicker than the other - da.UpdateCursor() once vs. multiple CalculateField_management calls.

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insert cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

@user2856159's answer is also good, I'd be curious to see if one method is any quicker than the other - da.UpdateCursor() once vs. multiple CalculateField_management calls.

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an update cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

@user2856159's answer is also good, I'd be curious to see if one method is any quicker than the other - da.UpdateCursor() once vs. multiple CalculateField_management calls.

added 178 characters in body
Source Link
Jason Bellino
  • 4.3k
  • 27
  • 35

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insert cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

@user2856159's answer is also good, I'd be curious to see if one method is any quicker than the other - da.UpdateCursor() once vs. multiple CalculateField_management calls.

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insert cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insert cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")

@user2856159's answer is also good, I'd be curious to see if one method is any quicker than the other - da.UpdateCursor() once vs. multiple CalculateField_management calls.

Source Link
Jason Bellino
  • 4.3k
  • 27
  • 35

The help article for the AddField_management function states that it "Returns a delimited field name." See the example code in the document for proper usage.

Essentially what you are specifying as your SQL expression is a string which, depending on the data source, will be either "GeoLabel" or [GeoLabel]. What I think you are trying to do here is get the value of the field each record and assign it to the new field, which you can do by creating a cursor object, at which point you might as well use an insert cursor to update the new field instead of the calculate field tool. Your code would look something like this:

import os
import arcpy
from arcpy import env
env.overwriteOutput = 1  

inputFC = arcpy.GetParameterAsText(0)
inputField = arcpy.GetParameterAsText(1)
inputFieldLabel = "GeoLabel"
output = arcpy.AddFieldDelimiters(inputFC, inputField)
inputFieldName = arcpy.GetParameterAsText(2)

#Add the GeoLabel field to the Selected Feature Class
arcpy.AddField_management(inputFC, inputFieldLabel, "TEXT")

#Get value of the inputFieldLabel field and update the new field with that value
with arcpy.da.UpdateCursor(inputFC,inputField,inputFieldLabel) as cur:
    for row in cur:
        row[2] = row[1]
        cur.updateRow(row)

#Calculate the field values for the selected field, using UniueID field and InputFieldName
#arcpy.CalculateField_management(inputFC, inputFieldLabel, output, "Python_9.3")