Arcpy Calculate Field error

Discussion created by zackb11 on Jan 31, 2014
Latest reply on Jan 31, 2014 by mvolz47
Hi all,

I have a simple script that adds a field to a set of feature classes

for fc in fcList:
        arcpy.AddMessage("Fields added...")

In the above example: Source, FieldType2, and fieldLength all refer back to variables containing the field name (sourcefile), the field type (text)
and field Length (75)

For the next step I want to cycle through the feature classes again. This time, populating the sourcefile field with the feature class name; in this case, it would be fc.

for fc in fcList:

The first code snippet runs without error. The text field of length 75 is added.

The second code snippet gives the following error:

Traceback (most recent call last):
File "T:\JOBS\123110494\gis_data\spatial_data\project_discipline\modeling\scripts\HWard\", line 242, in <module>
File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\", line 3129, in CalculateField
raise e
ExecuteError: ERROR 000539: Error running expression: fc
Traceback (most recent call last):
File "<expression>", line 1, in <module>
NameError: name 'fc' is not defined

Failed to execute (CalculateField).

Failed to execute (master).

I've tried putting single quotes around fc ('fc'), tried it without quotes (fc), and even tried converting it to a string (str(fc)), but nothing seems to work.

I've also tried replacing "fc" with "test", and I get the same error, but in that case, it tells me "test" does not exist.

Any thoughts would be greatly appreciated.

Thanks in advance