<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Arcpy Calculate Field error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213335#M16423</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a simple script that adds a field to a set of feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc,Source,FieldType2,fieldLength)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields added...")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the above example: Source, FieldType2, and fieldLength all refer back to variables containing the field name (sourcefile), the field type (text)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and field Length (75)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc,Source,"fc","PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first code snippet runs without error. The text field of length 75 is added.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second code snippet gives the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "T:\JOBS\123110494\gis_data\spatial_data\project_discipline\modeling\scripts\HWard\add_calc_dissolve.py", line 242, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_management(fc,Source,"fc","PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3129, in CalculateField&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 000539: Error running expression: fc &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'fc' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (master).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Z&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 16:11:30 GMT</pubDate>
    <dc:creator>ZackBartlett</dc:creator>
    <dc:date>2021-12-12T16:11:30Z</dc:date>
    <item>
      <title>Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213335#M16423</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi all, &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a simple script that adds a field to a set of feature classes&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddField_management(fc,Source,FieldType2,fieldLength)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Fields added...")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the above example: Source, FieldType2, and fieldLength all refer back to variables containing the field name (sourcefile), the field type (text)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and field Length (75)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for fc in fcList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(fc,Source,"fc","PYTHON")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The first code snippet runs without error. The text field of length 75 is added.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The second code snippet gives the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "T:\JOBS\123110494\gis_data\spatial_data\project_discipline\modeling\scripts\HWard\add_calc_dissolve.py", line 242, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; arcpy.CalculateField_management(fc,Source,"fc","PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 3129, in CalculateField&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; raise e&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 000539: Error running expression: fc &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'fc' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (master).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any thoughts would be greatly appreciated.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks in advance&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Z&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 16:11:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213335#M16423</guid>
      <dc:creator>ZackBartlett</dc:creator>
      <dc:date>2021-12-12T16:11:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213336#M16424</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;show your full script, it looks like it is losing reference to your feature class list&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 13:55:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213336#M16424</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-01-31T13:55:13Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213337#M16425</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I've uploaded the full script as an attachment. For simplicity in my original post, I removed the other calculate field functions. They were working fine, anyway.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problematic code is at line 242.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 14:09:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213337#M16425</guid>
      <dc:creator>ZackBartlett</dc:creator>
      <dc:date>2014-01-31T14:09:11Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213338#M16426</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Zack,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have a toolbox that takes a workspace of feature classes &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;and adds a column to each feature class (called orgFilNam 'Original File &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Name')and populates each feature within each feature class with its &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;filename.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It sound similar to what you are after, if you send me a private message with your email address I will forward it on to you. I can't upload it to this post at the moment as I am only on my iPad&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Anthony&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 14:21:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213338#M16426</guid>
      <dc:creator>AnthonyGiles</dc:creator>
      <dc:date>2014-01-31T14:21:40Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213339#M16427</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Zack:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Does your script work for the shapefile but not the geodatabase.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the shapefile you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(fc,Source,str(fc), "PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For the geodatabase you have:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;arcpy.CalculateField_management(fc,Source,"fc","PYTHON")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Why is this different?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 14:45:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213339#M16427</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-31T14:45:07Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213340#M16428</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have not tried running the script on shapefiles, so I'm not sure if this works. But I have tried using the str(fc) code in the geodatabase file. Still no luck.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 15:34:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213340#M16428</guid>
      <dc:creator>ZackBartlett</dc:creator>
      <dc:date>2014-01-31T15:34:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy Calculate Field error</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213341#M16429</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Can you add a print statement for str(fc) to see exactly what that is returning just before using it in the CalculateField_management statement?&amp;nbsp; That might provide a clue to your problem.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Jan 2014 15:55:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculate-field-error/m-p/213341#M16429</guid>
      <dc:creator>MichaelVolz</dc:creator>
      <dc:date>2014-01-31T15:55:07Z</dc:date>
    </item>
  </channel>
</rss>

