<?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: Problem creating function containing CalculateField in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381031#M69844</link>
    <description>&lt;P&gt;Try using an f-string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(dataset_out, input3, f"int({input1})* int({input2})")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The f-string will sub in a variable into the string, just like using "int({})* int({})".format(input1,&amp;nbsp;input2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;(I think that's the syntax for the old way? I don't use it anymore.)&amp;nbsp;&lt;/STRIKE&gt; Okay, that was &lt;A href="https://www.w3schools.com/python/ref_string_format.asp" target="_blank" rel="noopener"&gt;actually a correct way&lt;/A&gt; lol.&lt;/P&gt;</description>
    <pubDate>Mon, 12 Feb 2024 14:44:49 GMT</pubDate>
    <dc:creator>AlfredBaldenweck</dc:creator>
    <dc:date>2024-02-12T14:44:49Z</dc:date>
    <item>
      <title>Problem creating function containing CalculateField</title>
      <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1380794#M69843</link>
      <description>&lt;P&gt;I am very new to both arcgis and python. I am trying to define a function that takes in an input shape file, 2 fields from the file to perform a calculation on, a new field in the file to store the calculation, and an output shapefile name.&lt;/P&gt;&lt;P&gt;I have set up the following in Jupyter:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimPennington_0-1707623280725.png" style="width: 519px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94411iC73ED2D13D8F9E26/image-dimensions/519x143?v=v2" width="519" height="143" role="button" title="TimPennington_0-1707623280725.png" alt="TimPennington_0-1707623280725.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;When I call the function:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimPennington_3-1707623519615.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94414iA0F56C88DD84EEAD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TimPennington_3-1707623519615.png" alt="TimPennington_3-1707623519615.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I get the following error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimPennington_1-1707623374196.png" style="width: 545px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94412i2B9A6FF0D20CDF23/image-dimensions/545x109?v=v2" width="545" height="109" role="button" title="TimPennington_1-1707623374196.png" alt="TimPennington_1-1707623374196.png" /&gt;&lt;/span&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimPennington_2-1707623387902.png" style="width: 553px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94413i3BFB91F217899401/image-dimensions/553x101?v=v2" width="553" height="101" role="button" title="TimPennington_2-1707623387902.png" alt="TimPennington_2-1707623387902.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I add lines to the function to print the inputs, and comment out CalculateField I get :&lt;/P&gt;&lt;P&gt;!Height!&lt;/P&gt;&lt;P&gt;!Area!&lt;/P&gt;&lt;P&gt;!Volume!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have also tried just passing field 1 and field 2 into CalculateField and I get the same error.&lt;/P&gt;&lt;P&gt;If I run CalculateField without using the function, it runs with expected results.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimPennington_4-1707623589169.png" style="width: 533px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/94415iD24EC1A6DCDBA99F/image-dimensions/533x40?v=v2" width="533" height="40" role="button" title="TimPennington_4-1707623589169.png" alt="TimPennington_4-1707623589169.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I am not sure what I need to do to pass the parameters of the function through CalculateField.&lt;/P&gt;&lt;P&gt;Any guidance available would be greatly appreciated. Thank You!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Feb 2024 03:59:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1380794#M69843</guid>
      <dc:creator>TimPennington</dc:creator>
      <dc:date>2024-02-11T03:59:02Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating function containing CalculateField</title>
      <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381031#M69844</link>
      <description>&lt;P&gt;Try using an f-string:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(dataset_out, input3, f"int({input1})* int({input2})")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The f-string will sub in a variable into the string, just like using "int({})* int({})".format(input1,&amp;nbsp;input2)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRIKE&gt;(I think that's the syntax for the old way? I don't use it anymore.)&amp;nbsp;&lt;/STRIKE&gt; Okay, that was &lt;A href="https://www.w3schools.com/python/ref_string_format.asp" target="_blank" rel="noopener"&gt;actually a correct way&lt;/A&gt; lol.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 14:44:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381031#M69844</guid>
      <dc:creator>AlfredBaldenweck</dc:creator>
      <dc:date>2024-02-12T14:44:49Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating function containing CalculateField</title>
      <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381161#M69852</link>
      <description>&lt;P&gt;I think&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/458875"&gt;@AlfredBaldenweck&lt;/a&gt;&amp;nbsp;is correct here. You could also format your field names with the exclamations in this f-string instead of as separate variables. Also, the second parameter (&lt;SPAN&gt;field) doesn't need the exclamations.&lt;/SPAN&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.management.CalculateField(dataset_out, field3, f"int(!{field1}!) * int(!{field2}!)")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Feb 2024 17:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381161#M69852</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-02-12T17:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating function containing CalculateField</title>
      <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381384#M69855</link>
      <description>&lt;P&gt;Thank you so much for this! Took care of my issue!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 00:23:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381384#M69855</guid>
      <dc:creator>TimPennington</dc:creator>
      <dc:date>2024-02-13T00:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: Problem creating function containing CalculateField</title>
      <link>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381385#M69856</link>
      <description>&lt;P&gt;Thank you very much for helping with this!&lt;/P&gt;</description>
      <pubDate>Tue, 13 Feb 2024 00:24:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problem-creating-function-containing/m-p/1381385#M69856</guid>
      <dc:creator>TimPennington</dc:creator>
      <dc:date>2024-02-13T00:24:18Z</dc:date>
    </item>
  </channel>
</rss>

