<?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 Re: arcpy.CalculateField_management) is not passing variable in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565752#M44300</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Woohoo!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I highly recommend using nested quotes and substitution - easier to read and debug. This is equivalent to your solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CalculateField_management(species, "TypeName", \ &amp;nbsp;&amp;nbsp;&amp;nbsp; '"{0}"'.format(nameVariable), "PYTHON")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 10 Mar 2013 04:32:57 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2013-03-10T04:32:57Z</dc:date>
    <item>
      <title>arcpy.CalculateField_management) is not passing variable</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565749#M44297</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Running as python script within toolbox in ArcGIS 10.1.&amp;nbsp; Trying to say that if file is empty, populate the fields "TypeName","PERCENTAGE", "Region" with the following values: nameVariable, 0, "Georgia", otherwise, populate the table fields "Region" with "Georgia" and the field "TypeName" with "Goldfish". I cannot seem to populate the TypeName field with a variable. What am I doing wrong. I have spent two days on this and I cannot figure it out!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# Geonet conversion put code in a single line.&amp;nbsp; Below is another user's attempt to get python indentation
# fixed to make sense of the "answer".&amp;nbsp; Should be good thru line 20....not sure after that.

import os.path 
import arcpy 
import arcgisscripting&amp;nbsp; 
myList = ("Fish", "Reptile","Aracnid", "Other") 
geoLoc = "C:\\Data\\TempData.gdb\\"&amp;nbsp; 
for variablefile in myList:
&amp;nbsp; #&amp;nbsp; Assigning variables&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; species = geoLoc + (variablefile)+ "_Buffer"&amp;nbsp; 
&amp;nbsp; # setting nameVariable&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
&amp;nbsp; if variablefile == "Fish":
&amp;nbsp;&amp;nbsp;&amp;nbsp; nameVariable = "Goldfish"
&amp;nbsp; elif variablefile == "Reptile":
&amp;nbsp;&amp;nbsp;&amp;nbsp; nameVariable = "Tree frog"
&amp;nbsp; elif variablefile == "Aracnid":
&amp;nbsp;&amp;nbsp;&amp;nbsp; nameVariable = "Black widow"
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; nameVariable = "Household pet"
&amp;nbsp; addRow =arcpy.da.InsertCursor(species,("TypeName","PERCENTAGE", "Region"))
&amp;nbsp; result = int(arcpy.GetCount_management(species).getOutput(0))
&amp;nbsp; if result == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; addRow.insertRow((nameVariable, 0, "Georgia"))
&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(species, "Region", "\"Georgia\"", "PYTHON", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CalculateField_management(species, "TypeName", 'nameVariable', "PYTHON", "")
&amp;nbsp;&amp;nbsp;&amp;nbsp; #arcpy.CalculateField_management(species, "Name", "\"Goldfish\"", "PYTHON", "")&amp;nbsp; Works but doesn't use variable name&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
exit&amp;nbsp; 


&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;I get the following error message:&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;ExecuteError: ERROR 000539: Error running expression: commonName&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Traceback (most recent call last):&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp; File "&amp;lt;expression&amp;gt;", line 1, in &amp;lt;module&amp;gt;&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;NameError: name 'commonName' is not defined&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;SPAN&gt;Pretty sure it is failing at nameVariable (bold).&amp;nbsp; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks in advance.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Question from Mar 8, 2013 6:51 PM Message was edited by: Timothy Hales Formatted Code Block&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Message was edited by: Timothy Hales&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 00:22:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565749#M44297</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2021-12-12T00:22:43Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.CalculateField_management) is not passing variable</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565750#M44298</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Oops. Sorry. Copied wrong message. (That happens when you spend days on a single line of code. You get punchy and careless.) The actual message is:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;ExecuteError: ERROR 000539: Error running expression: nameVariable&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 'nameVariable' is not defined&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Happens on last executable line before "Exit"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Still stuck on this. Can't figure out how to get it to do what I want. Hopefully with the correct error message, someone can figure this out for me. I don't know where to go from here.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Mar 2013 01:20:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565750#M44298</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-10T01:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.CalculateField_management) is not passing variable</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565751#M44299</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Had a eureka moment and figured it out. Correct format is: &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;arcpy.CalculateField_management(species, "TypeName", "\"nameVariable\"", "PYTHON", "")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Woohoo!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Mar 2013 02:28:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565751#M44299</guid>
      <dc:creator>ClaudineSicker</dc:creator>
      <dc:date>2013-03-10T02:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.CalculateField_management) is not passing variable</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565752#M44300</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Woohoo!&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I highly recommend using nested quotes and substitution - easier to read and debug. This is equivalent to your solution:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;arcpy.CalculateField_management(species, "TypeName", \ &amp;nbsp;&amp;nbsp;&amp;nbsp; '"{0}"'.format(nameVariable), "PYTHON")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 10 Mar 2013 04:32:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-calculatefield-management-is-not-passing/m-p/565752#M44300</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-03-10T04:32:57Z</dc:date>
    </item>
  </channel>
</rss>

