<?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: Calculate field with Python codeblock in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705915#M23384</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I, too, have a hard time figuring out the correct scripting syntax for things like Calculate Field.&amp;nbsp; The foolproof way is to execute the tool using its dialog then open the &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_the_Results_window/002100000013000000/"&gt;Results window&lt;/A&gt; (10.0) or the &lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Working_with_Results"&gt;Results tab (9.3)&lt;/A&gt;, right-click the result and click "Copy as Python snippet".&amp;nbsp; This copies the code snippet to the clipboard and you can then paste it into your script.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Executing the tool to get the code snippet sort of defeats the purpose of writing a script (you just executed the tool in order to figure out how to execute the tool).&amp;nbsp; So I usually execute the tool on a toy dataset in order to get the snippet.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would be nice if this actually worked.&amp;nbsp; I have tried it on several python snippets to no avail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As an example, the script located here: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/2937-auto-sequential-numbers-with-python?p=62103#post62103"&gt;http://forums.arcgis.com/threads/2937-auto-sequential-numbers-with-python?p=62103#post62103&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; works perfectly from the calculator (or calculate fields) tool, but will not run as a python script.&amp;nbsp; I have exported to python as well as the copy to python listed here, and the syntax is not correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Professional ESRI beta tester&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 14 Dec 2010 18:45:49 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2010-12-14T18:45:49Z</dc:date>
    <item>
      <title>Calculate field with Python codeblock</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705911#M23380</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am attempting to calculate a field in a parent join layer using a field in the child join table. I am getting the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;[INDENT]&amp;lt;class 'arcgisscripting.ExecuteError'&amp;gt;: ERROR 000539: Error running expression: getSchool() &amp;lt;type 'exceptions.TypeError'&amp;gt;: getSchool() takes exactly 1 argument (0 given)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (CalculateField).[/INDENT]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The funny thing is, that it appears to work. Unfortunately, since I get this error the rest of the script doesn't run. Here is the code for the CalculateField line:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;gp.CalculateField_management("PS_lyr_out", "ScenarioTemplate_1011_temp.ES_06", 
"getSchool(!NAME!)", "PYTHON_9.3", 
"def getSchool(school):\\n&amp;nbsp; if (school &amp;lt;&amp;gt; \"NULL\"):\\n&amp;nbsp;&amp;nbsp;&amp;nbsp; return school\\n")
&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 29 Sep 2010 17:52:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705911#M23380</guid>
      <dc:creator>deleted-user-rQoEFM5qzbHE</dc:creator>
      <dc:date>2010-09-29T17:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Python codeblock</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705912#M23381</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Does your parameter in the call to getSchool need to have the join table name in it?&amp;nbsp; Something like "getSchool(!JoinTable.NAME!)"?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Sep 2010 21:42:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705912#M23381</guid>
      <dc:creator>JoeVondracek</dc:creator>
      <dc:date>2010-09-30T21:42:08Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Python codeblock</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705913#M23382</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yeah, I realized that after I submitted my question. I also was struggling to figure out how to set up the code block, but have since figured that out. Thanks for the reply.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Oct 2010 13:04:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705913#M23382</guid>
      <dc:creator>deleted-user-rQoEFM5qzbHE</dc:creator>
      <dc:date>2010-10-01T13:04:24Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Python codeblock</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705914#M23383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I, too, have a hard time figuring out the correct scripting syntax for things like Calculate Field.&amp;nbsp; The foolproof way is to execute the tool using its dialog then open the &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_the_Results_window/002100000013000000/"&gt;Results window&lt;/A&gt;&lt;SPAN&gt; (10.0) or the &lt;/SPAN&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Working_with_Results"&gt;Results tab (9.3)&lt;/A&gt;&lt;SPAN&gt;, right-click the result and click "Copy as Python snippet".&amp;nbsp; This copies the code snippet to the clipboard and you can then paste it into your script.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Executing the tool to get the code snippet sort of defeats the purpose of writing a script (you just executed the tool in order to figure out how to execute the tool).&amp;nbsp; So I usually execute the tool on a toy dataset in order to get the snippet.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 04 Oct 2010 17:26:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705914#M23383</guid>
      <dc:creator>DaleHoneycutt</dc:creator>
      <dc:date>2010-10-04T17:26:32Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field with Python codeblock</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705915#M23384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I, too, have a hard time figuring out the correct scripting syntax for things like Calculate Field.&amp;nbsp; The foolproof way is to execute the tool using its dialog then open the &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Using_the_Results_window/002100000013000000/"&gt;Results window&lt;/A&gt; (10.0) or the &lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=Working_with_Results"&gt;Results tab (9.3)&lt;/A&gt;, right-click the result and click "Copy as Python snippet".&amp;nbsp; This copies the code snippet to the clipboard and you can then paste it into your script.&amp;nbsp; &lt;BR /&gt;&lt;BR /&gt;Executing the tool to get the code snippet sort of defeats the purpose of writing a script (you just executed the tool in order to figure out how to execute the tool).&amp;nbsp; So I usually execute the tool on a toy dataset in order to get the snippet.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Would be nice if this actually worked.&amp;nbsp; I have tried it on several python snippets to no avail.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;As an example, the script located here: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/2937-auto-sequential-numbers-with-python?p=62103#post62103"&gt;http://forums.arcgis.com/threads/2937-auto-sequential-numbers-with-python?p=62103#post62103&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp; works perfectly from the calculator (or calculate fields) tool, but will not run as a python script.&amp;nbsp; I have exported to python as well as the copy to python listed here, and the syntax is not correct.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;R_&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Professional ESRI beta tester&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 14 Dec 2010 18:45:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-with-python-codeblock/m-p/705915#M23384</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2010-12-14T18:45:49Z</dc:date>
    </item>
  </channel>
</rss>

